Implement malloc-based SegmentAllocator #250
No reviewers
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi!250
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "malloc-allocate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When a memory segment is passed to a native function with full ownership transfer, the native function will free the memory. Until now, java-gi used
Arena.global()to allocate this memory, to prevent a double-free, but this is not guaranteed to work. It is better to actually use malloc to allocate the memory.The
mallocfunction we use isg_try_malloc0. This means the newly allocated memory will be zero-initialized. If the allocation fails, it returnsnull. In that case, java-gi will raise anInteropException.The allocator contains a workaround to be able to allocate zero-length memory segments (common in Java, but not supported by
g_malloc).