code: public static UnsafeHeapBuffer allocate(long initialCapacity, long maxCapacity) {
      if (initialCapacity > maxCapacity)
        throw new IllegalArgumentException("initial capacity cannot be greater than maximum capacity");
      if (initialCapacity > HeapMemory.MAX_SIZE)
        throw new IllegalArgumentException("initial capacity for HeapBuffer cannot be greater than " + HeapMemory.MAX_SIZE);
      if (maxCapacity > HeapMemory.MAX_SIZE)
        throw new IllegalArgumentException("maximum capacity for HeapBuffer cannot be greater than " + HeapMemory.MAX_SIZE);
      return new UnsafeHeapBuffer(new UnsafeHeapBytes(HeapMemory.allocate(Memory.Util.toPow2(initialCapacity))), 0, initialCapacity, maxCapacity);
    }
docs: Allocates a new heap buffer.
  <p>
  When the buffer is constructed, {@link HeapMemoryAllocator} will be used to allocate
  {@code capacity} bytes of memory on the Java heap. The resulting buffer will have an initial capacity of
  {@code initialCapacity} and will be doubled up to {@code maxCapacity} as bytes are written to the buffer. The
  underlying {@link UnsafeHeapBytes} will be initialized to the next power of {@code 2}.
  
  @param initialCapacity The initial capacity of the buffer to allocate (in bytes).
  @param maxCapacity The maximum capacity of the buffer.
  @return The heap buffer.
  @throws IllegalArgumentException If {@code initialCapacity} or {@code maxCapacity} is greater than the
  maximum allowed count for an array on the Java heap - {@code Integer.MAX_VALUE - 5}
  
  @see UnsafeHeapBuffer#allocate()
  @see UnsafeHeapBuffer#allocate(long)