{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiarj3sy4um6svde4ybpnlikiqzcvgryd6k2352dge2kpwg4rthbgy",
    "uri": "at://did:plc:dxjzgxe7cvirxkwfjr2tjspt/app.bsky.feed.post/3mkiubyep3t42"
  },
  "path": "/t/the-use-of-foreign-memory-api-in-game-engine/49572#post_3",
  "publishedAt": "2026-04-27T15:54:46.000Z",
  "site": "https://hub.jmonkeyengine.org",
  "tags": [
    "https://www.youtube.com/watch?v=lVORyDhQzf8"
  ],
  "textContent": "In my project I am using memory segments to store the positions of vertices of the terrain.\nI alloc a big memory segment that will be used for many tiles (before profiling the allocation took a big percentage of execution time).\n\nIn my first version of the game, I used Bytebuffers, in that version I needed to calculate the number of bytes I need to alloc. One of the reasons I tryed use memory segments was the struct layouts,wich I can ask for the size and offsets in the struct:\n\npublic static final StructLayout BUFFER_LAYOUT = structLayout(\nsequenceLayout(N_VERTICES_PER_TILE, sequenceLayout(3, JAVA_FLOAT)).withName(POSITION_ELEMENT),\nsequenceLayout(N_VERTICES_PER_TILE, sequenceLayout(3, JAVA_FLOAT)).withName(NORMAL_ELEMENT)\n);\n\nprivate static final MemorySegment MEMORY = Arena.ofConfined().allocate(structLayout(sequenceLayout(MAX_TILES_STORED, BUFFER_LAYOUT)));\n\nstatic final long POSITION_OFFSET = BUFFER_LAYOUT.byteOffset(PathElement.groupElement(POSITION_ELEMENT));\nstatic final long NORMAL_OFFSET = BUFFER_LAYOUT.byteOffset(PathElement.groupElement(NORMAL_ELEMENT));\nstatic final long POSITION_SIZE = BUFFER_LAYOUT.select(PathElement.groupElement(POSITION_ELEMENT)).byteSize();\nstatic final long NORMAL_SIZE = BUFFER_LAYOUT.select(PathElement.groupElement(NORMAL_ELEMENT)).byteSize();\n\nThe video that make me try to use it and learn a little:\nhttps://www.youtube.com/watch?v=lVORyDhQzf8",
  "title": "The use of Foreign Memory API in game engine"
}