Skip to content

Clean up and simplify zone memory allocation

Hanicef requested to merge Hanicef/SRB2:fix-memory-bloat into next

A continuation on !2050 (merged), cleaning up z_zone.c and simplifying it's use. Main differences are:

  • Allocations are now always aligned to pointer alignments, which mirrors the behavior of malloc.
  • Memory block and actual memory is now merged into the same allocation, which cuts the amount of allocations by half (might improve performance, but unlikely and not verified).
  • Memory header is merged with the memory block, to reduce complexity.

This is meant to fix memory bloat when allocating aligned memory, as something seems to be allocating an unreasonably large amount of memory in that case. My guess is that's it's due to the extra bytes that is used by alignbits, which is shifted by that value and is thus allocating memory exponentially.

Note that this touches calls to the Valgrind API, which I'm not very familiar with. If anyone spots something wrong related to Valgrind, let me know so I can fix it.

Merge request reports