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 org.graalvm.word.PointerBase>
Tcalloc(int size) Allocatessizebytes of unmanaged memory.static <T extends org.graalvm.word.PointerBase>
Tcalloc(org.graalvm.word.UnsignedWord size) Allocatessizebytes of unmanaged memory.static voidfree(org.graalvm.word.PointerBase ptr) Frees unmanaged memory that was previously allocated using methods of this class.static <T extends org.graalvm.word.PointerBase>
Tmalloc(int size) Allocatessizebytes of unmanaged memory.static <T extends org.graalvm.word.PointerBase>
Tmalloc(org.graalvm.word.UnsignedWord size) Allocatessizebytes of unmanaged memory.static <T extends org.graalvm.word.PointerBase>
Trealloc(T ptr, org.graalvm.word.UnsignedWord size) Changes the size of the provided unmanaged memory tosizebytes of unmanaged memory.
-
Method Details
-
malloc
public static <T extends org.graalvm.word.PointerBase> T malloc(org.graalvm.word.UnsignedWord size) Allocatessizebytes of unmanaged memory. The content of the memory is undefined.This method never returns a null pointer, but instead throws an
OutOfMemoryErrorwhen allocation fails.- Since:
- 19.0
-
malloc
public static <T extends org.graalvm.word.PointerBase> T malloc(int size) Allocatessizebytes of unmanaged memory. The content of the memory is undefined.This method never returns a null pointer, but instead throws an
OutOfMemoryErrorwhen allocation fails.- Since:
- 19.0
-
calloc
public static <T extends org.graalvm.word.PointerBase> T calloc(org.graalvm.word.UnsignedWord size) Allocatessizebytes of unmanaged memory. The content of the memory is set to 0.This method never returns a null pointer, but instead throws an
OutOfMemoryErrorwhen allocation fails.- Since:
- 19.0
-
calloc
public static <T extends org.graalvm.word.PointerBase> T calloc(int size) Allocatessizebytes of unmanaged memory. The content of the memory is set to 0.This method never returns a null pointer, but instead throws an
OutOfMemoryErrorwhen allocation fails.- Since:
- 19.0
-
realloc
public static <T extends org.graalvm.word.PointerBase> T realloc(T ptr, org.graalvm.word.UnsignedWord size) Changes the size of the provided unmanaged memory tosizebytes 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
OutOfMemoryErrorwhen allocation fails. In that case, the old data is not deallocated and remains unchanged.- Since:
- 19.0
-
free
public static void free(org.graalvm.word.PointerBase ptr) 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
-