Hi, I am creating a chess program. I am creating each piece on the board.

But when I try to compile the bishop piece I get this error
FATAL : Out of Memory in function set.

What does this mean?

i did a google on the error you posted but didnt get much (put it in quotes to hope to find someone with the same error)

doing a little rearranging this was the best i could find

Memory Leaks


A memory leak is a loss of available memory space. This occurs when dynamic data are no longer needed in the program, but the memory that is used has not been deallocated. It can also occur when an assignment is made to a pointer variable that already holds the address of an allocated area.
Each time a memory leak occurs, the application drains the available memory pool. Even in virtual-memory systems, the gradual increase in application size can result in performance degradation that affects the entire system. Eventually, this performance degradation can lead to a fatal out-of-memory condition that may be encountered by an application unrelated to the one that caused the memory leak in the first place.
Tip: make sure you match allocation calls with deallocation calls when doing unit testing, particularly where there might be an early return from a function where dynamic data was allocated. It's also essential to check, before assigning to a pointer, that the memory accessible via that pointer is freed prior to the assignment or made accessible some other way.

Memory Leaks


A memory leak is a loss of available memory space. This occurs when dynamic data are no longer needed in the program, but the memory that is used has not been deallocated. It can also occur when an assignment is made to a pointer variable that already holds the address of an allocated area.
Each time a memory leak occurs, the application drains the available memory pool. Even in virtual-memory systems, the gradual increase in application size can result in performance degradation that affects the entire system. Eventually, this performance degradation can lead to a fatal out-of-memory condition that may be encountered by an application unrelated to the one that caused the memory leak in the first place.
Tip: make sure you match allocation calls with deallocation calls when doing unit testing, particularly where there might be an early return from a function where dynamic data was allocated. It's also essential to check, before assigning to a pointer, that the memory accessible via that pointer is freed prior to the assignment or made accessible some other way.

How do get the memory back?

Suppose I have an array

char board[8][8]; ( This represents the chess board)

I want to store the PieceNo at each box on this board so that the computer can Identify which piece is there at that particular box.

For eg suppose at board[0][2] there is a white pawn. I want to store the value WP1 at the location board[0][2].

How can I do that?? Please help me.

> But when I try to compile the bishop piece I get this error
> FATAL : Out of Memory in function set.
Just so that we're all clear on this, this happens when you're compiling the code right?

Or does it mean the code has compiled OK, and this is what you get when you run the code.

I get it when I try to compile the code.

The most likely cause is that your source file is too big. This is either because you only have one source file, and it contains all the code, or you have many source files, but they're all #include 'ed in a since file which is then compiled.
The solution is to split the code up into separately compiled modules.

The next most likely cause is that you're using some ancient 16-bit fossil compiler, and you're using the wrong memory model. If your code (or data) exceeds 64K, and you've chosen the wrong memory model, then the program will no longer fit in memory.
The solution is to use the correct memory model for your project (see your compiler manual pages for details of how to do that).
A better solution is to use a modern 32-bit compiler and join the rest of the real world.

The solution is to split the code up into separately compiled modules.

Do you mean into different header files. Like some functions into different header files?

Can you tell any 32 bit compiler which supports graphics.h and functions like circle(x,y,rad); stuff like that.

Because for the chess program I require those.

Yes, drop the idea graphics.h as being the only thing which can do graphics.

For example, dev-c++ easily integrates with http://www.libsdl.org/

> Do you mean into different header files. Like some functions into different header files?
Yes, like you have
board.c - the implementation of a chess board
board.h - the interface to the chess board
pieces.c -
pieces.h
main.c - brings everything together.
The project file would contain 3 source files and two header files.

SDL seems to be good. I saw their website.

But I have to learn it fully which would take time. So I thought maybe for the chess progrm I shall continue with graphics as I have to submit the chess program by August 20 th

libsdl is a better choice than BGI since it has a host of functions and has better tutorials and support on the internet than BGI. Considering that you have one entire month for making the game, you can easily switch to libsdl and finish off the project.

Can you provide some links where I can download ebooks on SDL. because all the links I saw through google provide only short tuttorial.

But how much of libsdl were you planning to use?

I mean, some squares for the board, and some polygons for all the pieces, plus some simple I/O would seem to be all that you need (it's all BGI was going to give you anyway).

Sooner or later, you have to realise that there isn't necessarily a tutorial for everything out there, and it's up to you to read basic manual page type information and figure the rest out for yourself.

The solution is to use the correct memory model for your project (see your compiler manual pages for details of how to do that).
A better solution is to use a modern 32-bit compiler and join the rest of the real world.

And the best solution is to do both :)

libsdl is a better choice than BGI since it has a host of functions and has better tutorials and support on the internet than BGI.

Whatever it is, it's a better choice if it supports 32 bit environments as BGI is 16 bit only :)


The basic game engine should not contain any display related code.
Write everything without a display system and then write a display system you can plug that code into.
Make both independent of the other and have some interface between them.

he basic game engine should not contain any display related code.
Write everything without a display system and then write a display system you can plug that code into.
Make both independent of the other and have some interface between them.

I understand thanks.That's what I was doing. Kept all the graphics under one header file and the game logic in another.

I mean, some squares for the board, and some polygons for all the pieces, plus some simple I/O would seem to be all that you need (it's all BGI was going to give you anyway).

Yeah that's what I needed graphics for. But SDL gives you the option of loading .bmp files. Maybe I could use that feature instead of drawing the pieces myself.

> Maybe I could use that feature instead of drawing the pieces myself.
Maybe you could, but I would leave that until the end when you know you've got time to do it, and you have the backup of having something working already.

Don't waste the next 3 weeks fiddling with alternative graphical presentation styles. Pick something basic for the moment until the core game logic is working to your satisfaction.

How do you output a character in graphics mode?

I mean outtextxy(); outptuts only strings. Is there a function to output a single character?

Put the single character into a short string.
Easy isn't it?

yeah but the thing is everywhere I had used a char variable, so it would be difficult changing them all. Anyway I got an idea. I will copy the contents of the char to a string.

And then output it.

Put the single character into a short string.
Easy isn't it?

...

yeah but the thing is everywhere I had used a char variable, so it would be difficult changing them all. Anyway I got an idea. I will copy the contents of the char to a string.

And then output it.

I bet you never thought of doing it like that, eh, Salem :icon_rolleyes:

did anyone ask you bench?

> did anyone ask you bench?
Bad attitude. First in another thread and now this one. If you keep up this, I don't think you would be getting any help.

Always learn with an open mind and smile on your face otherwise getting help would become an herculian task.

I bet you never thought of doing it like that, eh, Salem

Sorry, I thought he was ridiculing salem that's it.

I think you missed the irony a little bit there... Salem posted a suggestion of putting the char into a string, then your reply contained "I got an idea..", where you went on to describe the same thing :)

I realise that might have been lost on some people ;)

Member Avatar for xander85

Suppose I have an array

char board[8][8]; ( This represents the chess board)

I want to store the PieceNo at each box on this board so that the computer can Identify which piece is there at that particular box.

For eg suppose at board[0][2] there is a white pawn. I want to store the value WP1 at the location board[0][2].

How can I do that?? Please help me.

To my knowledge char only stores one value i.e. 'e'... So how are you going to store a string in a char??? looks like you need => string board[8][8]???

I asked my friends they said that
board[64][4] would work.

there would 64 boxes in the board and each would store a string of 3 characters.

I think you missed the irony a little bit there... Salem posted a suggestion of putting the char into a string, then your reply contained "I got an idea..", where you went on to describe the same thing :)

I realise that might have been lost on some people ;)

bench don't bother, I am an idiot . .. misunderstood things...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.