Class Stdlib
java.lang.Object
com.github.marschall.nativebytebuffers.Stdlib
Provides access to memory management using
stdlib.h
.-
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBuffer
aligned_alloc
(int alignment, int size) Callscalloc()
and wraps the result in aByteBuffer
static ByteBuffer
calloc
(int size) Callscalloc()
and wraps the result in aByteBuffer
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 Details
-
malloc
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:
-
calloc
Callscalloc()
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 0 as percalloc()
contract, must be released withfree(ByteBuffer)
- Throws:
AllocationFailedException
- ifcalloc
returnsNULL
IllegalArgumentException
- ifsize
is not positive- See Also:
-
aligned_alloc
Callscalloc()
and wraps the result in aByteBuffer
- Parameters:
alignment
- the alignment in bytes, must bet power of 2 and least as large assizeof(void *)
size
- the number of bytes to allocate, must be positive, an integral multiple ofalignment
int
becauseByteBuffer
only supportsint
indices- Returns:
- the new buffer,
never
null
, the content is uninitialized as peraligned_alloc()
contract, must be released withfree(ByteBuffer)
- Throws:
AllocationFailedException
- ifaligned_alloc
returnsNULL
IllegalArgumentException
- ifalignment
is not positive, ifsize
is not positive- See Also:
-
free
Callsfree()
on the contents of the givenByteBuffer
.This method may crash the JVM the buffer passed has not been created by
malloc(int)
orcalloc(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:
-