summaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2025-11-28 23:20:58 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2025-11-28 23:20:58 +0100
commitff2942a46d943f2ef30ac74ef6ea75992a3ac26c (patch)
tree3dea0ec1313075577a51e898866a2c7fcce14688 /src/main/scala
parenteb08ce6d690852c99c576cc1216687c569df359e (diff)
feature: succesfully allocated memory on the heap ( or the off heap ) not sure what happened lol
Diffstat (limited to 'src/main/scala')
-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)
+ }
+ }
+}