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?
loadImage from graphics.h uses too much memory?
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.
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.
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.
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.