Skip to content

[Java] Allocator buffer method no setting the capacity correctly. #141

@FiV0

Description

@FiV0

Describe the bug, including details regarding any error messages, version, and platform.

The following snippet

package org.apache.arrow.vector;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.RootAllocator;
import org.junit.jupiter.api.Test;


public class BufferAllocatorOverAllocation {

    @Test
    void overallocation()  {
        RootAllocator allocator = new RootAllocator();
        ArrowBuf buf = allocator.buffer(9946);

        System.out.println(buf.capacity());

        buf.capacity(9946);

        System.out.println(buf.capacity());

    }

}

prints

16384
9946

So without setting the capacity explicitly the allocator overallocates memory and also seems to set the capacity of the buffer to that. That is contrary to the docstring of the buffer method:

Note that the buffer may technically be larger than the requested size for rounding purposes. However, the buffer's capacity will be set to the configured size.

Tested against the 14.0.2 tag.

Component(s)

Java

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions