Class Stdlib
java.lang.Object
com.github.marschall.nativebytebuffers.Stdlib
Provides access to memory management using
stdlib.h.-
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBufferaligned_alloc(int alignment, int size) Callscalloc()and wraps the result in aByteBufferstatic ByteBuffercalloc(int size) Callscalloc()and wraps the result in aByteBufferstatic voidfree(ByteBuffer buffer) Callsfree()on the contents of the givenByteBuffer.static ByteBuffermalloc(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,intbecauseByteBufferonly supportsintindices- Returns:
- the new buffer,
never
null, the content is uninitialized as permalloc()contract, must be released withfree(ByteBuffer) - Throws:
AllocationFailedException- ifmallocreturnsNULLIllegalArgumentException- ifsizeis not positive- See Also:
-
calloc
Callscalloc()and wraps the result in aByteBuffer- Parameters:
size- the number of bytes to allocate, must be positive,intbecauseByteBufferonly supportsintindices- Returns:
- the new buffer,
never
null, the content is 0 as percalloc()contract, must be released withfree(ByteBuffer) - Throws:
AllocationFailedException- ifcallocreturnsNULLIllegalArgumentException- ifsizeis 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 ofalignmentintbecauseByteBufferonly supportsintindices- Returns:
- the new buffer,
never
null, the content is uninitialized as peraligned_alloc()contract, must be released withfree(ByteBuffer) - Throws:
AllocationFailedException- ifaligned_allocreturnsNULLIllegalArgumentException- ifalignmentis not positive, ifsizeis 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- ifbufferisnullIllegalArgumentException- ifbufferis not a direct buffer- See Also:
-