Enum Class LibcArena
- All Implemented Interfaces:
Serializable,AutoCloseable,Comparable<LibcArena>,Constable,Arena,SegmentAllocator
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescription@NotNull MemorySegmentallocate(long byteSize, long byteAlignment) Allocates memory using system libc
aligned_allocNote that you're in charge of freeing the memory using
free(java.lang.foreign.MemorySegment), otherwise there will be a memory leak.voidclose()voidfree(@NotNull MemorySegment ms) Frees memory that was allocated byallocate(long, long).voidfreeNonAllocated(@NotNull MemorySegment ms) Frees memory that was allocated by libc allocator, but not viaallocate(long, long).scope()static LibcArenaReturns the enum constant of this class with the specified name.static LibcArena[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class java.lang.Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfMethods 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
-
Enum Constant Details
-
INSTANCE
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
allocate
Allocates memory using system libc
aligned_allocNote 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 usingLibcArenain combination withallocateseries methods.- Specified by:
allocatein interfaceArena- Specified by:
allocatein interfaceSegmentAllocator- Parameters:
byteSize- The size of the memory to allocatebyteAlignment- The alignment of the memory to allocate- Returns:
- A
MemorySegmentrepresenting the allocated memory with all bytes zeroed - Throws:
IllegalArgumentException- If the byte size or alignment is invalidOutOfMemoryError- If the memory allocation fails
-
free
Frees memory that was allocated byallocate(long, long).- Parameters:
ms- The memory segment to free
-
freeNonAllocated
Frees memory that was allocated by libc allocator, but not via
allocate(long, long).Some libraries, like
stb_vorbis, may allocate memory using libc allocators internally, and require you to free that memory usingfreefrom the same libc implementation. The best way to do this is to use thefreemethod encapsulation provided by that library integration. But if that is not available, this method can be used as an alternative with some risk.This function is marked as
Unsafe, because if the memory was not exactly allocated by the same allocatorLibcArenafound, it will lead to undefined behavior. This relates with platforms, build system and many other factors. Double check before really doing this. -
scope
-
close
public void close()- Specified by:
closein interfaceArena- Specified by:
closein interfaceAutoCloseable
-