-
Ell authored
gegl-scratch is a fast memory allocator, suitable for small (up to a few megabytes), short-lived (usually, but not necessarily, bound to the current stack-frame) allocations. Unlike alloca(), gimp- scratch doesn't use the stack, and is therefore safer, may outlive the current stackframe, and will also serve bigger requests, by falling-back to malloc(). The allocator itself is very simple: We keep a per-thread stack of cached memory blocks (allocated using the normal allocator). When serving an allocation request, we simply pop the top block off the stack, and return it. If the block is too small, we replace it with a big-enough block; if the stack is empty, we allocate a new block. When the block is freed, we push it back to the top of the stack. The idea is that the stacks will ultimately stabalize to contain blocks that can serve all the encountered allocation patterns, without needing to reisze any of the blocks; as a consequence, the amount of scratch memory allocated at any given time should really be kept to a minimum. Note that blocks may be allocated on one thread, and freed on another thread, without leaking memory, however, this is not an intended usage pattern, and may lead to suboptimal performance. This code was migrated from GIMP.
b99032d7