Skip to content

allow caller-defined allocation strategies for WorldSection#486

Closed
KaptainWutax wants to merge 4 commits into
MCRcortex:devfrom
KaptainWutax:dev
Closed

allow caller-defined allocation strategies for WorldSection#486
KaptainWutax wants to merge 4 commits into
MCRcortex:devfrom
KaptainWutax:dev

Conversation

@KaptainWutax
Copy link
Copy Markdown
Contributor

@KaptainWutax KaptainWutax commented Apr 20, 2026

This allows WorldSection acquisition to use caller-defined allocation strategies while preserving the existing default behavior and the public API surface. It uses MemorySegment instead of long[] to allow for off-heap + safe native access to the data without JNI. This also moves the implementation toward Java's supported FFM API, as the memory-access methods in Unsafe were deprecated for removal in JDK 23.

WorldSection.Allocator myCustomAllocator = new WorldSection.Allocator() {
    @Override
    public MemorySegment allocate(int lvl, int x, int y, int z, int size) {
        return MemorySegment.ofArray(new long[size]);
    }

    @Override
    public void release(MemorySegment segment) {
        // Leave it to the GC
    }
};

// Existing behavior
WorldSection section = engine.acquire(lvl, x, y, z, false);

// Custom allocator
WorldSection section = engine.acquire(lvl, x, y, z, false, myCustomAllocator);

@KaptainWutax
Copy link
Copy Markdown
Contributor Author

This approach isn't the best fit for the project. Closing this as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant