1. 01 Dec, 2018 3 commits
    • Ell's avatar
      5d1a79a3
    • Ell's avatar
      app: add scratch-total variable to the dashboard · 698d1af7
      Ell authored
      Add a scratch-total variable to the dashboard's misc group, showing
      the total amount of memory used by the scratch allocator.
      698d1af7
    • 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