• Ell's avatar
    app: add gimp-scratch allocator · a8a86552
    Ell authored
    gimp-scratch is a fast memory allocator (on the order of magnitude
    of alloca()), suitable for small (up to a few megabytes), short-
    lived (usually, bound to the current stack-frame) allocations.
    Unlike alloca(), gimp-scratch doesn't use the stack, and is
    therefore safer, 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.  When the block is freed, we push it back to
    the top of the stack (note that even though each thread uses a
    separate stack, blocks can be migrated between threads, i.e.,
    allocated on one thread, and freed on another thread, although this
    is not really an intended usage pattern.)  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.
    a8a86552
Makefile.am 14.2 KB