https://github.com/over-run/memstack
Memory stack for FFM API
https://github.com/over-run/memstack
Last synced: 9 months ago
JSON representation
Memory stack for FFM API
- Host: GitHub
- URL: https://github.com/over-run/memstack
- Owner: Over-Run
- License: mit
- Created: 2024-08-22T15:48:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-15T08:44:40.000Z (over 1 year ago)
- Last Synced: 2025-02-09T14:21:38.571Z (11 months ago)
- Language: Java
- Homepage: https://over-run.github.io/memstack/
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Memory stack
Memory stack for FFM API.
## Overview
```java
void main() {
// push a frame of the memory stack stored with thread-local variable
try (var stack = MemoryStack.pushLocal()) {
// allocate using methods in SegmentAllocator
// you should initialize the allocated memory segment at once, either by fill((byte)0) or C functions
var segment = stack.allocate(ValueLayout.JAVA_INT);
// pass to C functions
storeToPointer(segment);
// access the memory segment
readData(segment.get(ValueLayout.JAVA_INT, 0L));
}
// the memory stack automatically pops with try-with-resources statement
}
```
This is equivalent to C code:
```c
void storeToPointer(int* p) { *p = ...; }
void readData(int i);
int main() {
int i;
storeToPointer(&i);
readData(i);
}
```
## Download
Maven coordinate: `io.github.over-run:memstack:VERSION`
Gradle:
```groovy
dependencies {
implementation("io.github.over-run:memstack:0.3.0")
}
```