org.apache.cassandra.utils.memory

## Class SlabAllocator

- java.lang.Object
- - org.apache.cassandra.utils.memory.MemtableAllocator
  - - org.apache.cassandra.utils.memory.MemtableBufferAllocator
    - - org.apache.cassandra.utils.memory.SlabAllocator

-     public class SlabAllocator
      extends MemtableBufferAllocator

  + * The SlabAllocator is a bump-the-pointer allocator that allocates + * large (1MB) global regions and then doles them out to threads that + * request smaller sized (up to 128kb) slices into the array.

  The purpose of this class is to combat heap fragmentation in long lived objects: by ensuring that all allocations with similar lifetimes only to large regions of contiguous memory, we ensure that large blocks get freed up at the same time.

  Otherwise, variable length byte arrays allocated end up interleaved throughout the heap, and the old generation gets progressively more fragmented until a stop-the-world compacting collection occurs.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.cassandra.utils.memory.MemtableAllocator

      `MemtableAllocator.DataReclaimer, MemtableAllocator.SubAllocator`

  - ### Field Summary

    - ### Fields inherited from class org.apache.cassandra.utils.memory.MemtableAllocator

      `NO_OP`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.nio.ByteBuffer` | `allocate(int size)`
    `java.nio.ByteBuffer` | `allocate(int size, OpOrder.Group opGroup)`
    `protected AbstractAllocator` | `allocator(OpOrder.Group writeOp)`
    `MemtableAllocator.DataReclaimer` | `reclaimer()`
    `void` | `setDiscarded()` Indicate the memory and resources owned by this allocator are no longer referenced, and can be reclaimed/reused.

    - ### Methods inherited from class org.apache.cassandra.utils.memory.MemtableBufferAllocator

      `clone, clone, clone, clone, clone`

    - ### Methods inherited from class org.apache.cassandra.utils.memory.MemtableAllocator

      `isLive, offHeap, onHeap, setDiscarding`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### allocate

          public java.nio.ByteBuffer allocate(int size)

    - #### allocate

          public java.nio.ByteBuffer allocate(int size,
                                              OpOrder.Group opGroup)

      Specified by:
        `allocate` in class `MemtableBufferAllocator`

    - #### reclaimer

          public MemtableAllocator.DataReclaimer reclaimer()

      Specified by:
        `reclaimer` in class `MemtableAllocator`

    - #### setDiscarded

          public void setDiscarded()

      Description copied from class: `MemtableAllocator`
      Indicate the memory and resources owned by this allocator are no longer referenced, and can be reclaimed/reused.
      Overrides:
        `setDiscarded` in class `MemtableAllocator`

    - #### allocator

          protected AbstractAllocator allocator(OpOrder.Group writeOp)

      Overrides:
        `allocator` in class `MemtableBufferAllocator`

Copyright © 2018 The Apache Software Foundation