Class LibcArena
java.lang.Object
club.doki7.ffm.LibcArena
- All Implemented Interfaces:
AutoCloseable
,Arena
,SegmentAllocator
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription@NotNull MemorySegment
allocate
(long byteSize, long byteAlignment) Allocates memory using system libc
aligned_alloc
Note that you're in charge of freeing the memory using
free(java.lang.foreign.MemorySegment)
, otherwise there will be a memory leak.void
close()
void
free
(@NotNull MemorySegment ms) scope()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.foreign.SegmentAllocator
allocate, allocate, allocate, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom, allocateFrom
-
Field Details
-
INSTANCE
-
-
Method Details
-
free
-
allocate
Allocates memory using system libc
aligned_alloc
Note that you're in charge of freeing the memory using
free(java.lang.foreign.MemorySegment)
, otherwise there will be a memory leak. Be extra careful when usingLibcArena
in combination withallocate
series methods.- Specified by:
allocate
in interfaceArena
- Specified by:
allocate
in interfaceSegmentAllocator
- Parameters:
byteSize
- The size of the memory to allocatebyteAlignment
- The alignment of the memory to allocate- Returns:
- A
MemorySegment
representing the allocated memory with all bytes zeroed - Throws:
IllegalArgumentException
- If the byte size or alignment is invalidOutOfMemoryError
- If the memory allocation fails
-
scope
-
close
public void close()- Specified by:
close
in interfaceArena
- Specified by:
close
in interfaceAutoCloseable
-