Interface AllocationReservation

All Superinterfaces:
AutoCloseable

public interface AllocationReservation extends AutoCloseable
Supports cumulative allocation reservation. Clients may increase the size of the reservation repeatedly until they call for an allocation of the current total size. The reservation can only be used once, and will throw an exception if it is used more than once.

For the purposes of airtight memory accounting, the reservation must be close()d whether it is used or not. This is not threadsafe.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(int nBytes)
    Add to the current reservation.
    Allocate a buffer whose size is the total of all the add()s made.
    void
     
    int
    Get the current size of the reservation (the sum of all the add()s).
    boolean
    Return whether or not the reservation has been closed.
    boolean
    Return whether or not the reservation has been used.
    boolean
    reserve(int nBytes)
    Requests a reservation of additional space.
  • Method Details

    • add

      boolean add(int nBytes)
      Add to the current reservation.

      Adding may fail if the allocator is not allowed to consume any more space.

      Parameters:
      nBytes - the number of bytes to add
      Returns:
      true if the addition is possible, false otherwise
      Throws:
      IllegalStateException - if called after buffer() is used to allocate the reservation
    • reserve

      boolean reserve(int nBytes)
      Requests a reservation of additional space.

      The implementation of the allocator's inner class provides this.

      Parameters:
      nBytes - the amount to reserve
      Returns:
      true if the reservation can be satisfied, false otherwise
    • allocateBuffer

      ArrowBuf allocateBuffer()
      Allocate a buffer whose size is the total of all the add()s made.

      The allocation request can still fail, even if the amount of space requested is available, if the allocation cannot be made contiguously.

      Returns:
      the buffer, or null, if the request cannot be satisfied
      Throws:
      IllegalStateException - if called more than once
    • getSize

      int getSize()
      Get the current size of the reservation (the sum of all the add()s).
      Returns:
      size of the current reservation
    • isUsed

      boolean isUsed()
      Return whether or not the reservation has been used.
      Returns:
      whether or not the reservation has been used
    • isClosed

      boolean isClosed()
      Return whether or not the reservation has been closed.
      Returns:
      whether or not the reservation has been closed
    • close

      void close()
      Specified by:
      close in interface AutoCloseable