PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

running out of memory ?

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.
BurningSheep · 03 Nov 2002, 17:31 UTC
Do you have a code sample? I was thinking that maybe you are creating them on the stack, if so try creating them on the heap instead using the new operator.
yep, burningsheep is most probably right...
It's just strange that compiler doesn't give you error.
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 ???
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.
BurningSheep · 03 Nov 2002, 18:15 UTC
Conan wrote:
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 :(

Put the planet_data * planets in your class definition. And put the allocation in the PF init function like this:
Code:
planets = new planet_data[2000];

The declaration needs to be in the class definition to be accesible from the gameloop() function. And there should be no problem allocating space for it in gameinit()
Conan · 03 Nov 2002, 18:33 UTC — where to allocate
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 )
This is a C++ issue and has absolutely nothing to do with PF. I doubt that there is a lack of documentation on C++.

BTW, you don't have to use the game framework if you are unfamiliar with C++... You can use the display object directly.
Conan · 03 Nov 2002, 23:20 UTC — c++ documentation
when I say c++ lacks good documentation I really mean it. So many examples either assume so much or give such a trivial example. Just this week I have wasted several hours just looking for good examples so that I could understand the syntax when I already know what I want to do & just can't work out just what I'm supposed to do to make the commands operate. Most of these issues are related to the poor addressing modes and dire string support of C++ compared to any other language I have come across.

This is one reason why I spend so many hours writing articles. I try to save others from the pain I have to go through to understand a topic.

C++ may be the fast & flexible but it's a badly design system and sometimes seems to me to be close to not passing as a real programming language given the extent to which it's propped up by add-on functions. The old tale of it being designed to be difficult on purpose comes back to mind :roll:
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.
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
Id have to agree with using the new or malloc. MooMoo Pocket used dynamic memory and for fun i had it infinatly add cows. It got into the thousands before it was running too slow to actually tell if anything was happening :).