newlib malloc updated to prevent memory fragment
newlib malloc updated to prevent memory fragment
Hi, folks. Recently I found out if we update newlib-psp malloc version to the latest malloc-2.8.4, the memory fragment after a mass of allocating-and-freeing memory operations will significantly reduce.
I ported it to newlib-psp-1.17.0. If anyone who suffered from the memory fragment should test this patch.
Note:
1. Already use a spinlock to guarantee thread-safety, no need to define __malloc_lock.
2. Can be slightly slower than original. Or you can define INSECURE to 1 to skip the sanity check for speed.
Install:
wget ftp://sources.redhat.com/pub/newlib/new ... 7.0.tar.gz
tar -zxvf newlib-1.17.0.tar.gz
cd newlib-1.17.0
patch -p1 < ../newlib-1.17.0-psp-malloc-2.8.4.patch
./configure --prefix=$PSPDEV --target=psp && make && make install
patch download: http://ifile.it/kt2pqi9
I ported it to newlib-psp-1.17.0. If anyone who suffered from the memory fragment should test this patch.
Note:
1. Already use a spinlock to guarantee thread-safety, no need to define __malloc_lock.
2. Can be slightly slower than original. Or you can define INSECURE to 1 to skip the sanity check for speed.
Install:
wget ftp://sources.redhat.com/pub/newlib/new ... 7.0.tar.gz
tar -zxvf newlib-1.17.0.tar.gz
cd newlib-1.17.0
patch -p1 < ../newlib-1.17.0-psp-malloc-2.8.4.patch
./configure --prefix=$PSPDEV --target=psp && make && make install
patch download: http://ifile.it/kt2pqi9
I've gotten around to compiling this version of newlib using the following instructions above.
The Good News:
I went from 6246484 Bytes of fragmented memory to 4759612 Bytes. Thats about 23.8% Savings!
The Bad News:
I still have quite a bit of fragmented memory...
If anyone has any suggestions on how to lower fragmented memory or suggest another type of malloc where fragmented memory is even lower then please let me know.
The Good News:
I went from 6246484 Bytes of fragmented memory to 4759612 Bytes. Thats about 23.8% Savings!
The Bad News:
I still have quite a bit of fragmented memory...
If anyone has any suggestions on how to lower fragmented memory or suggest another type of malloc where fragmented memory is even lower then please let me know.
@SamuraiX try to use pools, it will reduce a lot your fragmentation if you have a lot of tiny allocations (ie. strings and structs/classes).
Another thing is to reduce your allocations, we are used to alloc much more than we really need.
My games have _almost_ none alloc/new (resource loading ONLY) and I have almost no fragmentation as all my resources are loaded at beginning of a game state and automatically unloaded when switching to another state. These basic things saved me from so much trouble.
Another thing is to reduce your allocations, we are used to alloc much more than we really need.
My games have _almost_ none alloc/new (resource loading ONLY) and I have almost no fragmentation as all my resources are loaded at beginning of a game state and automatically unloaded when switching to another state. These basic things saved me from so much trouble.