Top Description Constructors Methods
org.graalvm.nativeimage

public final Class UnmanagedMemory

extends Object
Class Inheritance
Imports
org.graalvm.nativeimage.impl.UnmanagedMemorySupport, org.graalvm.word.PointerBase, .UnsignedWord, .WordFactory

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <T extends PointerBase> T
calloc(UnsignedWord size)

Allocates size bytes of unmanaged memory.

public static <T extends PointerBase> T
calloc(int size)

Allocates size bytes of unmanaged memory.

public static void
free(PointerBase ptr)

Frees unmanaged memory that was previously allocated using methods of this class.

public static <T extends PointerBase> T
malloc(UnsignedWord size)

Allocates size bytes of unmanaged memory.

public static <T extends PointerBase> T
malloc(int size)

Allocates size bytes of unmanaged memory.

public static <T extends PointerBase> T
realloc(T ptr, UnsignedWord size)

Changes the size of the provided unmanaged memory to size bytes of unmanaged memory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

UnmanagedMemoryback to summary
private UnmanagedMemory()

Method Detail

callocback to summary
public static <T extends PointerBase> T calloc(UnsignedWord size)

Allocates size 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
callocback to summary
public static <T extends PointerBase> T calloc(int size)

Allocates size 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
freeback to summary
public static void free(PointerBase ptr)

Frees unmanaged memory that was previously allocated using methods of this class. This method is a no-op if the given pointer is null.

Since
19.0
mallocback to summary
public static <T extends PointerBase> T malloc(UnsignedWord size)

Allocates size 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
mallocback to summary
public static <T extends PointerBase> T malloc(int size)

Allocates size 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
reallocback to summary
public static <T extends PointerBase> T realloc(T ptr, UnsignedWord size)

Changes the size of the provided unmanaged memory to size 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