Class Stdlib
- java.lang.Object
-
- com.github.marschall.nativebytebuffers.Stdlib
-
public final class Stdlib extends Object
Provides access to memory management usingstdlib.h
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
free(ByteBuffer buffer)
Callsfree()
on the contents of the givenByteBuffer
.static ByteBuffer
malloc(int size)
Callsmalloc()
and wraps the result in aByteBuffer
-
-
-
Method Detail
-
malloc
public static ByteBuffer malloc(int size)
Callsmalloc()
and wraps the result in aByteBuffer
- Parameters:
size
- the number of bytes to allocate, must be positive,int
becauseByteBuffer
only supportsint
indices- Returns:
- the new buffer,
never
null
, the content is uninitialized as permalloc()
contract, must be released withfree(ByteBuffer)
- Throws:
AllocationFailedException
- ifmalloc
returnsNULL
IllegalArgumentException
- ifsize
is not positive- See Also:
free(ByteBuffer)
, MALLOC(3)
-
free
public static void free(ByteBuffer buffer)
Callsfree()
on the contents of the givenByteBuffer
.This method may crash the JVM the buffer passed has not been created by
malloc(int)
or has already been passed to this method.- Parameters:
buffer
- the buffer to free, notnull
, must have been created withmalloc(int)
, must not be accessed afterwards, must not be passed to this method again- Throws:
NullPointerException
- ifbuffer
isnull
IllegalArgumentException
- ifbuffer
is not a direct buffer- See Also:
- MALLOC(3)
-
-