Skip to content

Commit 776466e

Browse files
authored
GH-141: Correct capacity behavior in BufferAllocator.buffer docstrings (#1010)
## What's Changed Update the `BufferAllocator.buffer(long)` and `BufferAllocator.buffer(long, BufferManager)` docstrings so they match the actual behavior: the returned buffer’s capacity is the allocated (possibly rounded) size, not the requested size. The previous text said the capacity would be set to the configured size, which was incorrect. The new text also mentions that callers can use `ArrowBuf#capacity(long)` to set the capacity to the requested size when needed. Documentation-only change; no code or behavioral changes. Closes #141.
1 parent b3113ab commit 776466e

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public long capacity() {
136136
/**
137137
* Adjusts the capacity of this buffer. Size increases are NOT supported.
138138
*
139-
* @param newCapacity Must be in in the range [0, length).
139+
* @param newCapacity Must be in the range [0, length).
140140
*/
141141
public synchronized ArrowBuf capacity(long newCapacity) {
142142

memory/memory-core/src/main/java/org/apache/arrow/memory/BufferAllocator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
public interface BufferAllocator extends AutoCloseable {
2626

2727
/**
28-
* Allocate a new or reused buffer of the provided size. Note that the buffer may technically be
29-
* larger than the requested size for rounding purposes. However, the buffer's capacity will be
30-
* set to the configured size.
28+
* Allocate a new or reused buffer of the provided size. The buffer may be larger than the
29+
* requested size for rounding purposes (e.g. to a power of two), and the buffer's capacity will
30+
* reflect the actual allocated size. Use {@link ArrowBuf#capacity(long)} to set the capacity to
31+
* the requested size if needed.
3132
*
3233
* @param size The size in bytes.
3334
* @return a new ArrowBuf, or null if the request can't be satisfied
@@ -36,9 +37,10 @@ public interface BufferAllocator extends AutoCloseable {
3637
ArrowBuf buffer(long size);
3738

3839
/**
39-
* Allocate a new or reused buffer of the provided size. Note that the buffer may technically be
40-
* larger than the requested size for rounding purposes. However, the buffer's capacity will be
41-
* set to the configured size.
40+
* Allocate a new or reused buffer of the provided size. The buffer may be larger than the
41+
* requested size for rounding purposes (e.g. to a power of two), and the buffer's capacity will
42+
* reflect the actual allocated size. Use {@link ArrowBuf#capacity(long)} to set the capacity to
43+
* the requested size if needed.
4244
*
4345
* @param size The size in bytes.
4446
* @param manager A buffer manager to manage reallocation.

0 commit comments

Comments
 (0)