Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Last active November 2, 2022 16:26
Show Gist options
  • Save BetterProgramming/2703ee6c4d659dc7e6a9be9a225aa3d9 to your computer and use it in GitHub Desktop.
Save BetterProgramming/2703ee6c4d659dc7e6a9be9a225aa3d9 to your computer and use it in GitHub Desktop.
import org.graalvm.nativeimage.c.struct.SizeOf;
import static org.graalvm.nativeimage.UnmanagedMemory.calloc;
import static org.graalvm.nativeimage.UnmanagedMemory.malloc;
public static CSpeechBusinessData allocData() {
// malloc() initializes only. allocated space is dirty.
CSpeechBusinessData csbd = malloc(
SizeOf.get(CSpeechBusinessData.class)
);
return csbd;
}
// allocate an array of *
public static WordPointer allocArray(int size) {
// calloc() initializes and sanitizes
return calloc(size * SizeOf.get(WordPointer.class));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment