Top Description Inners Fields Constructors Methods
org.lwjgl.system

public Class MemoryStack

extends Default
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Known Direct Subclasses
org.lwjgl.system.MemoryStack.DebugMemoryStack
Imports
org.lwjgl.*, javax.annotation.*, java.nio.*, java.util.*

An off-heap memory stack.

This class should be used in a thread-local manner for stack allocations.

See Also
Configuration#STACK_SIZE, Configuration#DEBUG_STACK

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MemoryStack.DebugMemoryStack

Stores the method that pushed a frame and checks if it is the same method when the frame is popped.

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private static final int
private static final int
protected int
private int[]
private int
private final int
private static final ThreadLocal<MemoryStack>
Inherited from org.lwjgl.system.Pointer.Default:
ADDRESSaddressBUFFER_CAPACITYBUFFER_CONTAINERBUFFER_LIMITBUFFER_MARKBUFFER_POSITIONUNSAFE

Constructor Summary

AccessConstructor and Description
protected
MemoryStack(ByteBuffer
the backing memory buffer, may be null
container
,
long
the backing memory address
address
,
int
the backing memory size
size
)

Creates a new MemoryStack backed by the specified memory region.

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer
ASCII(CharSequence
the text to encode
text
)

Encodes the specified text on the stack using ASCII encoding and returns a ByteBuffer that points to the encoded text, including a null-terminator.

public ByteBuffer
ASCII(CharSequence
the text to encode
text
,
boolean
if true, a null-terminator is included at the end of the encoded text
nullTerminated
)

Encodes the specified text on the stack using ASCII encoding and returns a ByteBuffer that points to the encoded text.

public ByteBuffer
ASCIISafe(CharSequence text)

Like ASCII, but returns null if text is null.

public ByteBuffer
ASCIISafe(CharSequence text, boolean nullTerminated)

Like ASCII, but returns null if text is null.

public ByteBuffer
bytes(byte x)

Single value version of malloc.

public ByteBuffer
bytes(byte x, byte y)

Two value version of malloc.

public ByteBuffer
bytes(byte x, byte y, byte z)

Three value version of malloc.

public ByteBuffer
bytes(byte x, byte y, byte z, byte w)

Four value version of malloc.

public ByteBuffer
bytes(byte... values)

Vararg version of malloc.

public ByteBuffer
calloc(int alignment, int size)

Calloc version of malloc(int, int).

public ByteBuffer
calloc(int size)

Calloc version of malloc(int).

public CLongBuffer
callocCLong(int size)

CLong version of calloc(int).

public DoubleBuffer
callocDouble(int size)

Double version of calloc(int).

public FloatBuffer
callocFloat(int size)

Float version of calloc(int).

public IntBuffer
callocInt(int size)

Int version of calloc(int).

public LongBuffer
callocLong(int size)

Long version of calloc(int).

public PointerBuffer
callocPointer(int size)

Pointer version of calloc(int).

public ShortBuffer
callocShort(int size)

Short version of calloc(int).

private static void
checkAlignment(int alignment)

private void
checkPointer(int pointer)

public CLongBuffer
clongs(long x)

Single value version of mallocCLong.

public CLongBuffer
clongs(long x, long y)

Two value version of mallocCLong.

public CLongBuffer
clongs(long x, long y, long z)

Three value version of mallocCLong.

public CLongBuffer
clongs(long x, long y, long z, long w)

Four value version of mallocCLong.

public CLongBuffer
clongs(long... values)

Vararg version of mallocCLong.

public void
close()

Implements java.lang.AutoCloseable.close.

Calls pop on this MemoryStack.
public static MemoryStack
create()

Creates a new MemoryStack with the default size.

public static MemoryStack
create(int
the maximum number of bytes that may be allocated on the stack
capacity
)

Creates a new MemoryStack with the specified size.

public static MemoryStack
create(ByteBuffer
the backing memory buffer
buffer
)

Creates a new MemoryStack backed by the specified memory buffer.

public DoubleBuffer
doubles(double x)

Single value version of mallocDouble.

public DoubleBuffer
doubles(double x, double y)

Two value version of mallocDouble.

public DoubleBuffer
doubles(double x, double y, double z)

Three value version of mallocDouble.

public DoubleBuffer
doubles(double x, double y, double z, double w)

Four value version of mallocDouble.

public DoubleBuffer
doubles(double... values)

Vararg version of mallocDouble.

public FloatBuffer
floats(float x)

Single value version of mallocFloat.

public FloatBuffer
floats(float x, float y)

Two value version of mallocFloat.

public FloatBuffer
floats(float x, float y, float z)

Three value version of mallocFloat.

public FloatBuffer
floats(float x, float y, float z, float w)

Four value version of mallocFloat.

public FloatBuffer
floats(float... values)

Vararg version of mallocFloat.

private void
public long
getAddress()

Returns the address of the backing off-heap memory.

public int
getFrameIndex()

Returns the current frame index.

public int
getPointer()

Returns the current stack pointer.

public long
getPointerAddress()

Returns the memory address at the current stack pointer.

public int
getSize()

Returns the size of the backing off-heap memory.

public IntBuffer
ints(int x)

Single value version of mallocInt.

public IntBuffer
ints(int x, int y)

Two value version of mallocInt.

public IntBuffer
ints(int x, int y, int z)

Three value version of mallocInt.

public IntBuffer
ints(int x, int y, int z, int w)

Four value version of mallocInt.

public IntBuffer
ints(int... values)

Vararg version of mallocInt.

public LongBuffer
longs(long x)

Single value version of mallocLong.

public LongBuffer
longs(long x, long y)

Two value version of mallocLong.

public LongBuffer
longs(long x, long y, long z)

Three value version of mallocLong.

public LongBuffer
longs(long x, long y, long z, long w)

Four value version of mallocLong.

public LongBuffer
longs(long... more)

Vararg version of mallocLong.

public ByteBuffer

Returns:

the allocated buffer
malloc
(int
the required buffer alignment
alignment
,
int
the number of elements in the buffer
size
)

Allocates an aligned ByteBuffer on the stack.

public ByteBuffer

Returns:

the allocated buffer
malloc
(int
the number of elements in the buffer
size
)

Allocates a ByteBuffer on the stack with alignment equal to POINTER_SIZE.

public CLongBuffer
mallocCLong(int size)

CLong version of malloc(int).

public DoubleBuffer
mallocDouble(int size)

Double version of malloc(int).

public FloatBuffer
mallocFloat(int size)

Float version of malloc(int).

public IntBuffer
mallocInt(int size)

Int version of malloc(int).

public LongBuffer
mallocLong(int size)

Long version of malloc(int).

public PointerBuffer
mallocPointer(int size)

Pointer version of malloc(int).

public ShortBuffer
mallocShort(int size)

Short version of malloc(int).

public int
nASCII(CharSequence
the text to encode
text
,
boolean
if true, a null-terminator is included at the end of the encoded text
nullTerminated
)

Encodes the specified text on the stack using ASCII encoding and returns the encoded text length, in bytes.

public int
nASCIISafe(CharSequence text, boolean nullTerminated)

Like nASCII, but returns 0 if text is null.

public long
nbyte(byte value)

Unsafe version of bytes(byte).

public long

Returns:

the memory address on the stack for the requested allocation
ncalloc
(int
the required element alignment
alignment
,
int
num the number of elements to allocate
num
,
int
the size of each element
size
)

Allocates a block of memory on the stack for an array of num elements, each of them size bytes long, and initializes all its bits to zero.

public long
nclong(long value)

Unsafe version of clongs(long).

public static MemoryStack
ncreate(long
the backing memory address
address
,
int
the backing memory size
size
)

Creates a new MemoryStack backed by the specified memory region.

public long
ndouble(double value)

Unsafe version of doubles(double).

public long
nfloat(float value)

Unsafe version of floats(float).

public long
nint(int value)

Unsafe version of ints(int).

public long
nlong(long value)

Unsafe version of longs(long).

public long

Returns:

the memory address on the stack for the requested allocation
nmalloc
(int
the allocation size
size
)

Calls nmalloc(int, int) with alignment equal to POINTER_SIZE.

public long

Returns:

the memory address on the stack for the requested allocation
nmalloc
(int
the required alignment
alignment
,
int
the allocation size
size
)

Allocates a block of size bytes of memory on the stack.

public long
npointer(long value)

Unsafe version of pointers(long).

public long
npointer(Pointer value)

Unsafe version of pointers(Pointer).

public long
npointer(Buffer value)

Unsafe version of pointers(Buffer).

public long
nshort(short value)

Unsafe version of shorts(short).

public static long
nstackCalloc(int alignment, int num, int size)

Thread-local version of ncalloc.

public static long
nstackMalloc(int size)

Thread-local version of nmalloc(int).

public static long
nstackMalloc(int alignment, int size)

Thread-local version of nmalloc(int, int).

public int
nUTF16(CharSequence
the text to encode
text
,
boolean
if true, a null-terminator is included at the end of the encoded text
nullTerminated
)

Encodes the specified text on the stack using UTF16 encoding and returns the encoded text length, in bytes.

public int
nUTF16Safe(CharSequence text, boolean nullTerminated)

Like nUTF16, but returns 0 if text is null.

public int
nUTF8(CharSequence
the text to encode
text
,
boolean
if true, a null-terminator is included at the end of the encoded text
nullTerminated
)

Encodes the specified text on the stack using UTF8 encoding and returns the encoded text length, in bytes.

public int
nUTF8Safe(CharSequence text, boolean nullTerminated)

Like nUTF8, but returns 0 if text is null.

public PointerBuffer
pointers(long x)

Single value version of mallocPointer.

public PointerBuffer
pointers(long x, long y)

Two value version of mallocPointer.

public PointerBuffer
pointers(long x, long y, long z)

Three value version of mallocPointer.

public PointerBuffer
pointers(long x, long y, long z, long w)

Four value version of mallocPointer.

public PointerBuffer
pointers(long... values)

Vararg version of mallocPointer.

public PointerBuffer
pointers(Pointer x)

Single value version of mallocPointer.

public PointerBuffer
pointers(Pointer x, Pointer y)

Two value version of mallocPointer.

public PointerBuffer
pointers(Pointer x, Pointer y, Pointer z)

Three value version of mallocPointer.

public PointerBuffer
pointers(Pointer x, Pointer y, Pointer z, Pointer w)

Four value version of mallocPointer.

public PointerBuffer
pointers(Pointer... values)

Vararg version of mallocPointer.

public PointerBuffer
pointers(Buffer x)

Single value version of mallocPointer.

public PointerBuffer
pointers(Buffer x, Buffer y)

Two value version of mallocPointer.

public PointerBuffer
pointers(Buffer x, Buffer y, Buffer z)

Three value version of mallocPointer.

public PointerBuffer
pointers(Buffer x, Buffer y, Buffer z, Buffer w)

Four value version of mallocPointer.

public PointerBuffer
pointers(Buffer... values)

Vararg version of mallocPointer.

public PointerBuffer

Returns:

a PointerBuffer containing the buffer's element addresses
pointersOfElements
(CustomBuffer<?>
the CustomBuffer to obtain its element addresses of
buffer
)

Allocates a new PointerBuffer of size buffer.remaining() and fills it with the addresses of the values within the provided CustomBuffer starting at buffer.position().

public MemoryStack

Returns:

this stack
pop
()

Pops the current stack frame and moves the stack pointer to the end of the previous stack frame.

public MemoryStack

Returns:

this stack
push
()

Stores the current stack pointer and pushes a new frame to the stack.

public void
setPointer(int pointer)

Sets the current stack pointer.

public ShortBuffer
shorts(short x)

Single value version of mallocShort.

public ShortBuffer
shorts(short x, short y)

Two value version of mallocShort.

public ShortBuffer
shorts(short x, short y, short z)

Three value version of mallocShort.

public ShortBuffer
shorts(short x, short y, short z, short w)

Four value version of mallocShort.

public ShortBuffer
shorts(short... values)

Vararg version of mallocShort.

public static ByteBuffer
stackASCII(CharSequence text)

Thread-local version of ASCII(CharSequence).

public static ByteBuffer
stackASCII(CharSequence text, boolean nullTerminated)

Thread-local version of ASCII(CharSequence, boolean).

public static ByteBuffer
stackASCIISafe(CharSequence text)

Thread-local version of ASCII(CharSequence).

public static ByteBuffer
stackASCIISafe(CharSequence text, boolean nullTerminated)

Thread-local version of ASCII(CharSequence, boolean).

public static ByteBuffer
stackBytes(byte x)

Thread-local version of bytes(byte).

public static ByteBuffer
stackBytes(byte x, byte y)

Thread-local version of bytes(byte, byte).

public static ByteBuffer
stackBytes(byte x, byte y, byte z)

Thread-local version of bytes(byte, byte, byte).

public static ByteBuffer
stackBytes(byte x, byte y, byte z, byte w)

Thread-local version of bytes(byte, byte, byte, byte).

public static ByteBuffer
stackBytes(byte... values)

Thread-local version of bytes(byte...).

public static ByteBuffer
stackCalloc(int size)

Thread-local version of calloc.

public static CLongBuffer
stackCallocCLong(int size)

Thread-local version of callocCLong.

public static DoubleBuffer
stackCallocDouble(int size)

Thread-local version of callocDouble.

public static FloatBuffer
stackCallocFloat(int size)

Thread-local version of callocFloat.

public static IntBuffer
stackCallocInt(int size)

Thread-local version of callocInt.

public static LongBuffer
stackCallocLong(int size)

Thread-local version of callocLong.

public static PointerBuffer
stackCallocPointer(int size)

Thread-local version of callocPointer.

public static ShortBuffer
stackCallocShort(int size)

Thread-local version of callocShort.

public static CLongBuffer
stackCLongs(long x)

Thread-local version of longs(long).

public static CLongBuffer
stackCLongs(long x, long y)

Thread-local version of longs(long, long).

public static CLongBuffer
stackCLongs(long x, long y, long z)

Thread-local version of longs(long, long, long).

public static CLongBuffer
stackCLongs(long x, long y, long z, long w)

Thread-local version of longs(long, long, long, long).

public static CLongBuffer
stackCLongs(long... values)

Thread-local version of longs(long...).

public static DoubleBuffer
stackDoubles(double x)

Thread-local version of doubles(double).

public static DoubleBuffer
stackDoubles(double x, double y)

Thread-local version of doubles(double, double).

public static DoubleBuffer
stackDoubles(double x, double y, double z)

Thread-local version of doubles(double, double, double).

public static DoubleBuffer
stackDoubles(double x, double y, double z, double w)

Thread-local version of doubles(double, double, double, double).

public static DoubleBuffer
stackDoubles(double... values)

Thread-local version of doubles(double...).

public static FloatBuffer
stackFloats(float x)

Thread-local version of floats(float).

public static FloatBuffer
stackFloats(float x, float y)

Thread-local version of floats(float, float).

public static FloatBuffer
stackFloats(float x, float y, float z)

Thread-local version of floats(float, float, float).

public static FloatBuffer
stackFloats(float x, float y, float z, float w)

Thread-local version of floats(float, float, float, float).

public static FloatBuffer
stackFloats(float... values)

Thread-local version of floats(float...).

public static MemoryStack
stackGet()

Returns the stack of the current thread.

public static IntBuffer
stackInts(int x)

Thread-local version of ints(int).

public static IntBuffer
stackInts(int x, int y)

Thread-local version of ints(int, int).

public static IntBuffer
stackInts(int x, int y, int z)

Thread-local version of ints(int, int, int).

public static IntBuffer
stackInts(int x, int y, int z, int w)

Thread-local version of ints(int, int, int, int).

public static IntBuffer
stackInts(int... values)

Thread-local version of ints(int...).

public static LongBuffer
stackLongs(long x)

Thread-local version of longs(long).

public static LongBuffer
stackLongs(long x, long y)

Thread-local version of longs(long, long).

public static LongBuffer
stackLongs(long x, long y, long z)

Thread-local version of longs(long, long, long).

public static LongBuffer
stackLongs(long x, long y, long z, long w)

Thread-local version of longs(long, long, long, long).

public static LongBuffer
stackLongs(long... values)

Thread-local version of longs(long...).

public static ByteBuffer
stackMalloc(int size)

Thread-local version of malloc.

public static CLongBuffer
stackMallocCLong(int size)

Thread-local version of mallocCLong.

public static DoubleBuffer
stackMallocDouble(int size)

Thread-local version of mallocDouble.

public static FloatBuffer
stackMallocFloat(int size)

Thread-local version of mallocFloat.

public static IntBuffer
stackMallocInt(int size)

Thread-local version of mallocInt.

public static LongBuffer
stackMallocLong(int size)

Thread-local version of mallocLong.

public static PointerBuffer
stackMallocPointer(int size)

Thread-local version of mallocPointer.

public static ShortBuffer
stackMallocShort(int size)

Thread-local version of mallocShort.

public static PointerBuffer
stackPointers(long x)

Thread-local version of pointers(long).

public static PointerBuffer
stackPointers(long x, long y)

Thread-local version of pointers(long, long).

public static PointerBuffer
stackPointers(long x, long y, long z)

Thread-local version of pointers(long, long, long).

public static PointerBuffer
stackPointers(long x, long y, long z, long w)

Thread-local version of pointers(long, long, long, long).

public static PointerBuffer
stackPointers(long... values)

Thread-local version of pointers(long...).

public static PointerBuffer
stackPointers(Pointer x)

Thread-local version of pointers(Pointer).

public static PointerBuffer
public static PointerBuffer
public static PointerBuffer
public static PointerBuffer
stackPointers(Pointer... values)

Thread-local version of pointers(Pointer...).

public static MemoryStack

Returns:

the stack of the current thread.
stackPop
()

Calls pop on the stack of the current thread.

public static MemoryStack

Returns:

the stack of the current thread.
stackPush
()

Calls push on the stack of the current thread.

public static ShortBuffer
stackShorts(short x)

Thread-local version of shorts(short).

public static ShortBuffer
stackShorts(short x, short y)

Thread-local version of shorts(short, short).

public static ShortBuffer
stackShorts(short x, short y, short z)

Thread-local version of shorts(short, short, short).

public static ShortBuffer
stackShorts(short x, short y, short z, short w)

Thread-local version of shorts(short, short, short, short).

public static ShortBuffer
stackShorts(short... values)

Thread-local version of shorts(short...).

public static ByteBuffer
stackUTF16(CharSequence text)

Thread-local version of UTF16(CharSequence).

public static ByteBuffer
stackUTF16(CharSequence text, boolean nullTerminated)

Thread-local version of UTF16(CharSequence, boolean).

public static ByteBuffer
stackUTF16Safe(CharSequence text)

Thread-local version of UTF16(CharSequence).

public static ByteBuffer
stackUTF16Safe(CharSequence text, boolean nullTerminated)

Thread-local version of UTF16(CharSequence, boolean).

public static ByteBuffer
stackUTF8(CharSequence text)

Thread-local version of UTF8(CharSequence).

public static ByteBuffer
stackUTF8(CharSequence text, boolean nullTerminated)

Thread-local version of UTF8(CharSequence, boolean).

public static ByteBuffer
stackUTF8Safe(CharSequence text)

Thread-local version of UTF8(CharSequence).

public static ByteBuffer
stackUTF8Safe(CharSequence text, boolean nullTerminated)

Thread-local version of UTF8(CharSequence, boolean).

public ByteBuffer
UTF16(CharSequence
the text to encode
text
)

Encodes the specified text on the stack using UTF16 encoding and returns a ByteBuffer that points to the encoded text, including a null-terminator.

public ByteBuffer
UTF16(CharSequence
the text to encode
text
,
boolean
if true, a null-terminator is included at the end of the encoded text
nullTerminated
)

Encodes the specified text on the stack using UTF16 encoding and returns a ByteBuffer that points to the encoded text.

public ByteBuffer
UTF16Safe(CharSequence text)

Like UTF16, but returns null if text is null.

public ByteBuffer
UTF16Safe(CharSequence text, boolean nullTerminated)

Like UTF16, but returns null if text is null.

public ByteBuffer
UTF8(CharSequence
the text to encode
text
)

Encodes the specified text on the stack using UTF8 encoding and returns a ByteBuffer that points to the encoded text, including a null-terminator.

public ByteBuffer
UTF8(CharSequence
the text to encode
text
,
boolean
if true, a null-terminator is included at the end of the encoded text
nullTerminated
)

Encodes the specified text on the stack using UTF8 encoding and returns a ByteBuffer that points to the encoded text.

public ByteBuffer
UTF8Safe(CharSequence text)

Like UTF8, but returns null if text is null.

public ByteBuffer
UTF8Safe(CharSequence text, boolean nullTerminated)

Like UTF8, but returns null if text is null.

Inherited from org.lwjgl.system.Pointer.Default:
addressequalshashCodetoString