Page 1 of 1

running out of memory ?

PostPosted: Nov 3, 2002 @ 5:56pm
by Conan
I have some structs with a few __int8 variables and a TCHAR[20]. When I try to create large numbers of these ( say 1000 or more ) the game hangs but lower numbers such as 500 work fine.

Each of these struct items is only 50 bytes so creating 1000 should only utilise 50Kb

Is there a way to test for lack of memory? My iPaq has a good amount of ram before running the game with just under 10Mb free for program and similar for storage.

I'm also trying to see if I'm just making a coding mistake somewhere and checking where it goes wrong in the debugger.

PostPosted: Nov 3, 2002 @ 6:31pm
by BurningSheep

PostPosted: Nov 3, 2002 @ 6:36pm
by MirekCz

PostPosted: Nov 3, 2002 @ 6:38pm
by Conan
I was not making use of new so I will try shortly. Currently here's what I am doing. This is in among all my other variable definitions none of which use new
:-
//struct definition
struct planet_data
{
__int8 p_octant;
__int8 p_sector;
__int8 p_race;
__int8 p_class;
__int8 p_techno;
__int8 p_civtype;
__int8 p_sysno;
__int8 p_sundist;
__int8 p_orbit
TCHAR p_name[20];
} planets[2000];

UPDATE: Yes, that works fine now as far as allocating the structs but now I cannot access the structs from functions as they are now created in PF's init function???. I am not understanding what PF requires of me obviously.
I tried defining the struct as follows:-

after the struct is defined I added
planet_data *planets and in the PF init I put
planet_data *planets = new planet_data[2000];
This builds but the game crashes so I'm still doing it wrong :(

I will transfer to the PocketFrog board now as this is not a general problem anymore. I can't define the variable using new within the only place in PF where I can define variables so the whole game can access them ???

PostPosted: Nov 3, 2002 @ 7:11pm
by Digby
You're almost certainly blowing out your stack. The stack limit for your application is set by a linker switch - /STACK:reserve[,commit]. The default set for a project using EVC 3.0 is /STACK:0x10000,0x1000. That's 64K max.

PostPosted: Nov 3, 2002 @ 7:15pm
by BurningSheep

where to allocate

PostPosted: Nov 3, 2002 @ 7:33pm
by Conan
BurningSheep, re your last reply that's what I tried but it crashed with an illegal operation. It may be that I just made a mistake so I will look again. I assumed that the definition within the class definition was not correctly tying up with the init's allocation

Update: My allocation statements were wrong. I checked against your syntax and it all works now. Many thanks for your help. ( every time I meet a new area I get bogged down in syntax. The lack of good examples in the online help means that I don't always see how to do things )

PostPosted: Nov 3, 2002 @ 10:28pm
by Kzinti

c++ documentation

PostPosted: Nov 4, 2002 @ 12:20am
by Conan

PostPosted: Nov 4, 2002 @ 1:40am
by Kzinti
I can understand where you are coming from. There is indeed quite a big hurdle to learning C++. It is close to the machine and definitely not user-friendly.

I myself started with assembler on my old CoCo 2 (a 6809 processor). I then moved to Pascal which as a much nicer syntax then C or C++. I then moved on to C and then C++. I had to chance to learn programming one thing at a time. I'm glad I didn't started with C++ from scratch.

PostPosted: Nov 4, 2002 @ 2:06am
by Dan East
Like Digby said, you are definitely running out of stack space. Typically for larger arrays you allocate them dynamically with new or malloc.

Dan East

PostPosted: Nov 7, 2002 @ 3:55am
by DillRye