Top Description Fields Constructors Methods
org.lwjgl.util.mapped

public abstract Class MappedObject

extends Object
Class Inheritance
Known Direct Subclasses
org.lwjgl.test.mapped.MappedFloat, org.lwjgl.test.mapped.MappedObjectTests3.Xyz, org.lwjgl.test.mapped.MappedObjectTests4.MappedPointer, org.lwjgl.test.mapped.MappedObjectTests4.MappedCacheLinePadded, org.lwjgl.test.mapped.MappedObjectTests4.MappedFieldCacheLinePadded, org.lwjgl.test.mapped.MappedSomething, org.lwjgl.test.mapped.MappedVec2, org.lwjgl.test.mapped.MappedVec3, org.lwjgl.test.opengl.sprites.SpriteShootoutMapped.Pixel4b, org.lwjgl.test.opengl.sprites.SpriteShootoutMapped.Pixel3b, org.lwjgl.test.opengl.sprites.SpriteShootoutMapped.Sprite, org.lwjgl.test.opengl.sprites.SpriteShootoutMapped.SpriteRender
Imports
org.lwjgl.LWJGLUtil, .MemoryUtil, java.nio.BufferOverflowException, .ByteBuffer

Base superclass of all mapped objects. Classes that require data mapping should extend this class and registered with MappedObjectTransformer#register(Class).

Subclasses may only specify the default constructor. Any code inside that constructor is optional, but will not run when the view is instantiated, see runViewConstructor().

Bounds checking may be enabled through a JVM system property: org.lwjgl.util.mapped.Checks=true

Author
Riven

Field Summary

Modifier and TypeField and Description
public long
baseAddress

The mapped object base memory address, in bytes.

pack-priv static final boolean
pack-priv ByteBuffer
preventGC

The mapped buffer.

public static int
SIZEOF

Holds the value of sizeof of the sub-type of this MappedObject The behavior of this (transformed) method does not follow the normal Java behavior.

public int
view

The mapped object view offset, in elements.

public long
viewAddress

The mapped object view memory address, in bytes.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public final <T extends MappedObject> T[]
public final ByteBuffer

Returns:

the backing buffer
backingByteBuffer
()

Returns the java.nio.ByteBuffer that backs this mapped object.

public final int

Returns:

the mapped object capacity
capacity
()

Returns the number of mapped objects that fit in the mapped buffer.

pack-priv final void
checkAddress(final long address)

pack-priv final void
checkRange(final int bytes)

public final <T extends MappedObject> void
copyRange(T target, int instances)

Copies and amount of SIZEOF * instances bytes, from the current mapped object, to the specified mapped object.

public final <T extends MappedObject> void
copyTo(T target)

Copies and amount of SIZEOF - padding bytes, from the current mapped object, to the specified mapped object.

public final <T extends MappedObject> T
dup()

Creates an identical new MappedObject instance, comparable to the contract of java.nio.ByteBuffer#duplicate.

public static <T extends MappedObject> Iterable<T>
foreach(T mapped)

Creates an Iterable <mappedobject> that will step through capacity() views, leaving the view at the last valid value.

public static <T extends MappedObject> Iterable<T>
foreach(T mapped, int elementCount)

Creates an Iterable <mappedobject> that will step through elementCount views, leaving the view at the last valid value.

public final int

Returns:

the memory alignment
getAlign
()

Returns the mapped object memory alignment, in bytes.

public final int

Returns:

the sizeof value
getSizeof
()

Returns the mapped object memory sizeof, in bytes.

protected final long
getViewAddress(final int view)

public static <T extends MappedObject> T
malloc(int elementCount)

Creates a MappedObject instance, mapping the memory region of an allocated direct ByteBuffer with a capacity of elementCount*SIZEOF

The behavior of this (transformed) method does not follow the normal Java behavior.

public static <T extends MappedObject> T
map(ByteBuffer bb)

Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer.

public static <T extends MappedObject> T
map(long address, int capacity)

Creates a MappedObject instance, mapping the memory region specified.

public final void
next()

Moves the current view to the next element.

public final void
runViewConstructor()

Any code in the default constructor will not run automatically.

public final void
setViewAddress(final long address)

public final <T extends MappedObject> T
slice()

Creates a new MappedObject instance, with a base offset equal to the offset of the current view, comparable to the contract of java.nio.ByteBuffer#slice.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseAddressback to summary
public long baseAddress

The mapped object base memory address, in bytes. Read-only.

CHECKSback to summary
pack-priv static final boolean CHECKS
preventGCback to summary
pack-priv ByteBuffer preventGC

The mapped buffer.

SIZEOFback to summary
public static int SIZEOF

Holds the value of sizeof of the sub-type of this MappedObject

The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.SIZEOF will yield 8 (2 floats)
Vec3.SIZEOF will yield 12 (3 floats)
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality.

viewback to summary
public int view

The mapped object view offset, in elements. Read/write. This is a virtual field, used as a convenient getter/setter for viewAddress.

See Also
viewAddress
viewAddressback to summary
public long viewAddress

The mapped object view memory address, in bytes. Read-only.

Constructor Detail

MappedObjectback to summary
protected MappedObject()

Method Detail

asArrayback to summary
public final <T extends MappedObject> T[] asArray()
Annotations
@SuppressWarnings:unused
backingByteBufferback to summary
public final ByteBuffer backingByteBuffer()

Returns the java.nio.ByteBuffer that backs this mapped object.

Returns:ByteBuffer

the backing buffer

capacityback to summary
public final int capacity()

Returns the number of mapped objects that fit in the mapped buffer.

Returns:int

the mapped object capacity

checkAddressback to summary
pack-priv final void checkAddress(final long address)
checkRangeback to summary
pack-priv final void checkRange(final int bytes)
copyRangeback to summary
public final <T extends MappedObject> void copyRange(T target, int instances)

Copies and amount of SIZEOF * instances bytes, from the current mapped object, to the specified mapped object. Note that this includes any padding bytes that are part of SIZEOF.

Annotations
@SuppressWarnings:unused
copyToback to summary
public final <T extends MappedObject> void copyTo(T target)

Copies and amount of SIZEOF - padding bytes, from the current mapped object, to the specified mapped object.

Annotations
@SuppressWarnings:unused
dupback to summary
public final <T extends MappedObject> T dup()

Creates an identical new MappedObject instance, comparable to the contract of java.nio.ByteBuffer#duplicate. This is useful when more than one views of the mapped object are required at the same time, e.g. in multithreaded access.

foreachback to summary
public static <T extends MappedObject> Iterable<T> foreach(T mapped)

Creates an Iterable that will step through capacity() views, leaving the view at the last valid value.

For convenience you are encouraged to static-import this specific method: import static org.lwjgl.util.mapped.MappedObject.foreach;

foreachback to summary
public static <T extends MappedObject> Iterable<T> foreach(T mapped, int elementCount)

Creates an Iterable that will step through elementCount views, leaving the view at the last valid value.

For convenience you are encouraged to static-import this specific method: import static org.lwjgl.util.mapped.MappedObject.foreach;

getAlignback to summary
public final int getAlign()

Returns the mapped object memory alignment, in bytes.

Returns:int

the memory alignment

getSizeofback to summary
public final int getSizeof()

Returns the mapped object memory sizeof, in bytes.

Returns:int

the sizeof value

getViewAddressback to summary
protected final long getViewAddress(final int view)
mallocback to summary
public static <T extends MappedObject> T malloc(int elementCount)

Creates a MappedObject instance, mapping the memory region of an allocated direct ByteBuffer with a capacity of elementCount*SIZEOF

The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.malloc(int) will return a mapped Vec2 instance.
Vec3.malloc(int) will return a mapped Vec3 instance.
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality.

Annotations
@SuppressWarnings:unused
mapback to summary
public static <T extends MappedObject> T map(ByteBuffer bb)

Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer.

The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.map(buffer) will return a mapped Vec2 instance.
Vec3.map(buffer) will return a mapped Vec3 instance.
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality.

Annotations
@SuppressWarnings:unused
mapback to summary
public static <T extends MappedObject> T map(long address, int capacity)

Creates a MappedObject instance, mapping the memory region specified. This is useful for mapping arbitrary regions in memory, e.g. OpenCL CLMem objects, without creating a ByteBuffer first.

The behavior of this (transformed) method does not follow the normal Java behavior.
Vec2.map(buffer) will return a mapped Vec2 instance.
Vec3.map(buffer) will return a mapped Vec3 instance.
This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").
Using Java 5.0's static-import on this method will break functionality.

Annotations
@SuppressWarnings:unused
nextback to summary
public final void next()

Moves the current view to the next element.

runViewConstructorback to summary
public final void runViewConstructor()

Any code in the default constructor will not run automatically. This method can be used to execute that code on the current view.

setViewAddressback to summary
public final void setViewAddress(final long address)
sliceback to summary
public final <T extends MappedObject> T slice()

Creates a new MappedObject instance, with a base offset equal to the offset of the current view, comparable to the contract of java.nio.ByteBuffer#slice.