Package org.graalvm.nativeimage
Class UnmanagedMemory
java.lang.Object
org.graalvm.nativeimage.UnmanagedMemory
Contains static methods that allow allocate/free of unmanaged memory, i.e., memory that is not
under the control of the garbage collector. In a typical C environment, these are the malloc/free
functions of the standard C library, however this class makes no assumptions or guarantees about
how the memory is managed. In particular, it is not allowed to free memory returned by these
allocation function directly using the standard C library (or vice versa).
- Since:
- 19.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends PointerBase>
Tcalloc
(int size) Allocatessize
bytes of unmanaged memory.static <T extends PointerBase>
Tcalloc
(UnsignedWord size) Allocatessize
bytes of unmanaged memory.static void
free
(PointerBase ptr) Frees unmanaged memory that was previously allocated using methods of this class.static <T extends PointerBase>
Tmalloc
(int size) Allocatessize
bytes of unmanaged memory.static <T extends PointerBase>
Tmalloc
(UnsignedWord size) Allocatessize
bytes of unmanaged memory.static <T extends PointerBase>
Trealloc
(T ptr, UnsignedWord size) Changes the size of the provided unmanaged memory tosize
bytes of unmanaged memory.
-
Method Details
-
malloc
Allocatessize
bytes of unmanaged memory. The content of the memory is undefined.This method never returns a null pointer, but instead throws an
OutOfMemoryError
when allocation fails.- Since:
- 19.0
-
malloc
Allocatessize
bytes of unmanaged memory. The content of the memory is undefined.This method never returns a null pointer, but instead throws an
OutOfMemoryError
when allocation fails.- Since:
- 19.0
-
calloc
Allocatessize
bytes of unmanaged memory. The content of the memory is set to 0.This method never returns a null pointer, but instead throws an
OutOfMemoryError
when allocation fails.- Since:
- 19.0
-
calloc
Allocatessize
bytes of unmanaged memory. The content of the memory is set to 0.This method never returns a null pointer, but instead throws an
OutOfMemoryError
when allocation fails.- Since:
- 19.0
-
realloc
Changes the size of the provided unmanaged memory tosize
bytes of unmanaged memory. If the new size is larger than the old size, the content of the additional memory is undefined.This method never returns a null pointer, but instead throws an
OutOfMemoryError
when allocation fails. In that case, the old data is not deallocated and remains unchanged.- Since:
- 19.0
-
free
Frees unmanaged memory that was previously allocated using methods of this class. This method is a no-op if the given pointer isnull
.- Since:
- 19.0
-