summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/main/domain/MemoryOperations.scala63
1 files changed, 34 insertions, 29 deletions
diff --git a/src/main/scala/main/domain/MemoryOperations.scala b/src/main/scala/main/domain/MemoryOperations.scala
index eb9649b..3e45470 100644
--- a/src/main/scala/main/domain/MemoryOperations.scala
+++ b/src/main/scala/main/domain/MemoryOperations.scala
@@ -3,47 +3,52 @@ package main.domain
import main.services._
import scala.util.hashing
-import scala.util.hashing.MurmurHash3 import scala.math._
+import scala.util.hashing.MurmurHash3
import scala.collection.immutable.ListSet
-import java.nio.ByteBuffer
+import scala.math._
+import java.lang.foreign._
+import java.lang.foreign.MemorySegment
+import java.lang.foreign.ValueLayout
+import scala.util.Using
-/**
- *
- * Large memory object to allocate on the heap
- * This is an implementation by me
- * A method to do this bassically an Array with large bytes allocated to it
- *
- * */
+object Memory {
-class MemoryObject {
-
- object size {
- val size: Int = 10 * 1024 * 1024
- }
-
- val buffer: Vector[size.type] = Vector(1, 1)
-}
+ /**
+ * Large memory object to allocate on the heap
+ * This is an implementation by me
+ * A method to do this bassically an Array with large bytes allocated to it
+ * */
+ class MemoryObject {
+ // TODO: create a large sized object
-/*
- * Using java.nio.ByteBuffer
- * Allocate memory then free memory
- * for stressing the memory we want to do some heavy heap allocations back and forth
- *
- *
- * */
+ }
-class MemoryAllocater extends ByteBuffer {
+ /*
+ * Using java.nio.ByteBuffer
+ * Allocate memory then free memory
+ * for stressing the memory we want to do some heavy heap allocations back and forth
+ * ---------
+ * not anymore
+ * switched to java.lang.foreign
+ *
+ * https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/foreign/package-summary.html
+ * */
- def run(): Unit = println("stressing memory")
+ class MemoryAllocater(arena: Arena) {
- def moveToMemory(): Unit ={
+ def run(): Unit = moveToMemory()
- }
-}
+ def moveToMemory(): Unit = {
+ val memseg = arena.allocate(10 * 4)
+ // not memseg.setAtIndex like in the docs :(
+ for i <- 0 to 10 do memseg.set(ValueLayout.JAVA_INT, i, i)
+ }
+ }
+}