[SDL] RLE Compression
rudolf.janz at gmx.net
Sun Apr 12 05:28:09 PDT 2009
>> Additionally this implementation uses a two pass RLE conversion. First the size of the resulting RLE compressed data is computed (by running the same algorithm on a dummy buffer).
>> THen the surface is actually compressed into a memory block of the right size. The RLE implementation in the current SDL allocates a worst case buffer (which in most cases is much too large) and reallocs that at the end, after the size is known. At least on Windows CE with the limited Virtual Memory (max. 32 MB, around 24 M usable) that leads to serious memory fragmentation.
> That's a shame. shrinking the most recently allocated chunk of memory
> should not cause memory fragmentation!
> A good libc allocator should not have a hard time with either approach.
It happens if there are other threads doing allocations. But even without other allocations, if realloc does not move the memory block, the amount of contiguous virtual memory is reduced, on a sane operating system, you would have at least 2GB of virtual memory so no problem.
On Windows CE it is just 32MB with around 10-12 MB already prefragmented (because of an incredibly stupid shared library loading mechanism)
In my case the avoiding the large estimates solved the out of memory problems.
More information about the SDL