954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Chess Program

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?

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

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?

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

> 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.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

I get it when I try to compile the code.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
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?

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

SDL seems to be good. I saw their website.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
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.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
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.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 
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.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

> 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.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

How do you output a character in graphics mode?

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You