Annotation Type MappedType


@Retention(RUNTIME) @Target(TYPE) public @interface MappedType
This annotation marks a class as a mapped object, which will go under bytecode transformation at runtime. Mapped objects cannot be instantiated directly; a data buffer must be mapped first and the mapped object instance will then be used as a view on top of the buffer. Instead of a separate instance per "element" in the buffer, only a single instance is used to manage everything. See MappedObject for API details and org.lwjgl.test.mapped.TestMappedObject for examples.

The instance fields of the annotated class should only be limited to primitive types or ByteBuffer. Static fields are supported and they can have any type.

The purpose of mapped objects is to reduce the memory requirements required for the type of data that are often used in OpenGL/OpenCL programming, while at the same time enabling clean Java code. There are also performance benefits related to not having to copy data between buffers and Java objects and the removal of bounds checking when accessing buffer data.

Author:
Riven
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The mapped data memory alignment, in bytes.
    boolean
    When autoGenerateOffsets is true, byte offsets of the mapped fields will be generated automatically.
    boolean
    When true, SIZEOF will be increased (if necessary) so that it's a multiple of the CPU cache line size.
    int
    The number of bytes to add to the total byte size.
  • Element Details

    • padding

      int padding
      The number of bytes to add to the total byte size. SIZEOF will be calculated as SIZEOF = max(field_offset + field_length) + padding.

      Cannot be used with cacheLinePadding().

      Returns:
      the padding amount
      Default:
      0
    • cacheLinePadding

      boolean cacheLinePadding
      When true, SIZEOF will be increased (if necessary) so that it's a multiple of the CPU cache line size. Additionally, MappedObject.malloc(int) on the mapped object type will automatically use CacheUtil.createByteBuffer(int) instead of the unaligned BufferUtils.createByteBuffer(int).

      Cannot be used with padding().

      Returns:
      if cache-line padding should be applied
      See Also:
      Default:
      false
    • align

      int align
      The mapped data memory alignment, in bytes.
      Returns:
      the memory alignment
      Default:
      4
    • autoGenerateOffsets

      boolean autoGenerateOffsets
      When autoGenerateOffsets is true, byte offsets of the mapped fields will be generated automatically. This is convenient for packed data. For manually aligned data, autoGenerateOffsets must be set to false and the user needs to manually specify byte offsets using the MappedField annotation.
      Returns:
      true if automatic byte offset generation is required.
      Default:
      true