 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
r0b3rt
Joined: 26 May 2008 Posts: 17
|
Posted: Thu Jun 05, 2008 12:23 am Post subject: loadImage from graphics.h uses too much memory? |
|
|
Hi.
I'm using graphics.h (and .c) from http://www.psp-programming.com/tutorials/c/lesson04.htm (and png.h) to load a png image (32x32).
Before calling 'loadImage' 'sceKernelTotalFreeMemSize' tells me I have 21 MB of RAM free, and after calling the 'loadImage' function, I have only 1 MB (1907kB) of RAM free.
After that, no matter how many png images I load, I always have 1907kB of RAM free. And 'freeImage' doesn't free any RAM.
Is there a bug in graphics.c or png.c?
Is there a better and safer way to load and display a png image? |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Thu Jun 05, 2008 9:22 pm Post subject: |
|
|
By default, the moment you allocate any memory, it will reserve the maximum possible memory for your application to further allocate from.
The actual Image structure will be only a few KB.
Use PSP_HEAP_SIZE_KB(value) to set the maximum amount of memory (in kilobytes) to reserve for your application.
If you use PSP_HEAP_SIZE_KB(1024) you can keep loading images upto 1MB but if you load anymore the PSP will crash.
If you are just making an EBOOT type application to run from the XMB, then just leave it at default. You only need to worry about reserving too much memory if you are making a plugin or PRX.
freeImage will only free the RAM *inside* the heap. The heap as a whole still exists and is reserved for your application.
In case you are making a plugin or PRX and need to free the RAM for other applications when you are done, use __psp_free_heap().
First declare the function prototype void __psp_free_heap(void);
Then call it when you need to clean up. |
|
| Back to top |
|
 |
r0b3rt
Joined: 26 May 2008 Posts: 17
|
Posted: Fri Jun 06, 2008 6:03 am Post subject: |
|
|
Thank you!
I also tried loading images using SDL and then tried just calling malloc in the main function - the result was the same. The entire RAM defined in PSP_HEAP_SIZE_KB wasn't free anymore. Then I tried loading an extenal prx, and it didn't work, because he had no memory to load.
Now, before loading the prx, I call __psp_free_heap(), and I also call it before exiting the prx, and everything works fine. So thanks once again, I now understand better how homebrews on PSP use memory. |
|
| Back to top |
|
 |
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|