free'ing memory

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

ok yea..that was a bad example.. well im not sure why what is happening to me is happening then.. i load up say maybe 40-50 pictures..different sized pictures..and free them all eventually.. and in the same program i load up a mp3 file, and play it.. it crashes..if i try a small mp3 file, it works fine..

now if i take the code that plays the mp3 file into a separate program..the big mp3 file will load and play fine.. so that leaves me to beleive the images i load and free..are not clearing memory completly..or is there some way i can .. like defrag the memory..heh.. so the mp3 has room to be loaded into?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

I don't know how to defrag the memory, but this is a PSPSDK related question, I've splitted your posting to this forum.
User avatar
jpadams
Posts: 23
Joined: Sat Jul 02, 2005 1:59 pm
Location: Los Angeles
Contact:

Post by jpadams »

are your malloc's aligned ?
thats the easiest way to cause a crash
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

Call malloc/free as few times as possible. If you are loading up a bunch of bitmaps, load up enough memory to hold your framebuffer ( 480x272x4bytes ) and write to that buffer whenever you load up an image. When you load the image, call malloc to grab enough memory to hold the file and then free it imediately afterwards, or better yet make a dedicated file-read buffer that is only created once.

This will cut down on the amount of memory fragmentation. Remember, you've only got about 20MB of real RAM to work with once your executable is loaded up. This is NOT a lot!
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

It's a lot more than PS1!! And we fitted a lot in that. As long as we have the reasonable expectation that if we free everything we malloc there is no fragmentation that is OK. And as long as the C++ object allocations aren't mental then there is some chance of reliable software.

Jim
PS. It's a lot more ram than N64 and DC.
Post Reply