This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Allocating Memory in CMyApplication


Allocating Memory in CMyApplication

Postby mlepage » Jan 16, 2004 @ 5:41am

If I take the minimal application (GapiDraw 2.05eval), and add one line to CMyApplication to allocate an array:

int array[240 * 240];

then when I launch the application, it locks the device before the splash screen is displayed.

If I drop it down to this amount:

char array[240 * 240];

then I get an actual dialogue which says illegal exception, and the device does not hang.

If I drop it down to this amount:

char array[240 * 210];

Then it works fine.

If I increase it to this amount:

char array[240 * 225];

Then I get the spinning wait cursor, for half a minute before I lose patience and reset the device.

So I assume I'm running out of memory. Yet 240 * 240 * 1 byte is only 56KB, which doesn't seem like a lot. Wouldn't surfaces take up 240 * 320 * 2 bytes which is even more?

Does anyone else see this behaviour? Can they allocate a 240x240 array of chars? ints? I'm using a release build for iPAQ 3970.
www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby ppcStudios » Jan 16, 2004 @ 11:48am

G.R. Moore
President/CEO
Pocket PC Studios
www.ppcstudios.com

Image
User avatar
ppcStudios
pm Insider
 
Posts: 744
Joined: Aug 23, 2002 @ 3:53pm
Location: Canfield, Ohio


Postby mlepage » Jan 16, 2004 @ 2:24pm

www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby Pam » Jan 16, 2004 @ 2:35pm

All the easy problems have been solved.
User avatar
Pam
pm Insider
 
Posts: 449
Joined: Jan 24, 2002 @ 10:30pm
Location: Ohio


Postby mlepage » Jan 16, 2004 @ 2:47pm

www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby Layre5150 » Feb 17, 2004 @ 3:52pm

I believe you are taxing the stack. If for example you have:

char cMyArray[128];
char cMyArray[128*100];

Which is allocated from the stack and is totally different than:

char* pMyArray = (char*)malloc( 128 * 100 * sizeof(char) );

Which comes from the heap.
Layre5150
pm Member
 
Posts: 21
Joined: Feb 13, 2004 @ 5:17pm


Postby Layre5150 » Feb 17, 2004 @ 3:55pm

I took a look at the date on that post which was posted about a month ago - sorry. I guess you probably would have solved it by now.
Layre5150
pm Member
 
Posts: 21
Joined: Feb 13, 2004 @ 5:17pm


Postby mlepage » Feb 18, 2004 @ 4:22am

Yup it was on the stack and I didn't really notice it was. :-)

In my older project I also allocated in CMyApplication, but I actually created the application instance on the heap so it was fine.

In my newer project, however, the instance is created on the stack just like the Minimal sample applicaiton.
www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby Layre5150 » Feb 18, 2004 @ 1:47pm

Layre5150
pm Member
 
Posts: 21
Joined: Feb 13, 2004 @ 5:17pm


Postby mlepage » Feb 18, 2004 @ 5:11pm

Well, I only allocate this at the beginning of the program run. So it's not a problem allocating and deallocating.

Further, if you allocate statically, apparently that would be a problem if you port to devices like Symbian.

The correct way to approach memory problems is to only write your own allocators once you've shown allocation to actually be a problem.

Right now it's not a problem for me, my app runs quite well.
www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Return to GapiDraw


Sort


Forum Description

The Cross-platform Graphics SDK for Palms, Pocket PCs, Symbian Devices, and Stationary PCs.

Moderators:

sponge, Johan

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron