summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2025-12-01 22:04:00 +0100
committernasr <nsrddyn@gmail.com>2025-12-01 22:04:00 +0100
commit6c6f8c93a41fafdab5715f25a8b94f24c38fec25 (patch)
treec596c90ced80c3b9689cc5009ec6841765181a5e /src
parent6837f651532eff9b9b978dc31d295c8edfdf8f72 (diff)
refactor: basic refactoring and taking care of TODO
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/main/domain/CpuOperations.scala3
-rw-r--r--src/main/scala/main/domain/MemoryOperations.scala28
-rw-r--r--src/main/scala/main/infrastructure/Resources.scala2
3 files changed, 21 insertions, 12 deletions
diff --git a/src/main/scala/main/domain/CpuOperations.scala b/src/main/scala/main/domain/CpuOperations.scala
index 328d65e..049b667 100644
--- a/src/main/scala/main/domain/CpuOperations.scala
+++ b/src/main/scala/main/domain/CpuOperations.scala
@@ -67,11 +67,8 @@ class Prime extends CPU {
*/
class Hash extends CPU {
-
def run(n: Int): Unit = {
-
for i <- 0 to n do MurmurHash3.stringHash("a random string to hash")
-
}
}
diff --git a/src/main/scala/main/domain/MemoryOperations.scala b/src/main/scala/main/domain/MemoryOperations.scala
index 81feff9..6fe43d9 100644
--- a/src/main/scala/main/domain/MemoryOperations.scala
+++ b/src/main/scala/main/domain/MemoryOperations.scala
@@ -26,6 +26,11 @@ import scala.util.Using
class MemoryAllocater {
+ /**
+ * = _ is deprecated, compiler tells me to use uninitialized values
+ * but when i try that it doesn't work so i'm stuck with the warning
+ * */
+
private var arena: Arena = _
private var memorySegment: MemorySegment = _
@@ -56,6 +61,7 @@ class MemoryAllocater {
*
* */
arena = Arena.global()
+ // convert one to long to have more space
memorySegment = arena.allocate(1024L * 1024 * 1024) // 1 GiB
}
@@ -65,15 +71,18 @@ class MemoryAllocater {
/**
* Checks if arena is created if it isn't call the createMemorySegment method
* Close the previous arena if there is one and initlizate values on a memory segment
+ *
+ * Note to self: there is no need to be taking a baseOffset,
+ * we arent the ones defining the starting position of a memory segment
* */
- def setValues(values: List[Int], baseOffset: Int): Unit = {
+ def setValues(values: List[Int], offset: Int): Unit = {
if this.arena == null then createMemorySegment
- val stride = Integer.BYTES.toLong
- val start = baseOffset.toLong
+ // val stride = Integer.BYTES.toLong
+ // val start = baseOffset.toLong
for (i <- values.indices) {
- val addr = start + (i * stride)
+ val addr = i * offset
memorySegment.set(ValueLayout.JAVA_INT, addr, values(i))
}
@@ -83,12 +92,17 @@ class MemoryAllocater {
* Retrieves the set values that were initialized on
* the off heap in the setValues method
* */
+
+ /**
+ * Note to self: there is no need to be taking a baseOffset,
+ * we arent the ones defining the starting position of a memory segment
+ * */
def getValues(offset: Int, len: Int): List[Int] = {
- val stride = Integer.BYTES.toLong
- val start = offset.toLong
+ // val stride = Integer.BYTES.toLong
+ // val start = offset.toLong
(0 until len).map { i =>
- val addr = start + (i * stride)
+ val addr = i * offset
memorySegment.get(ValueLayout.JAVA_INT, addr)
}.toList
}
diff --git a/src/main/scala/main/infrastructure/Resources.scala b/src/main/scala/main/infrastructure/Resources.scala
index bf9dcf7..62e17fa 100644
--- a/src/main/scala/main/infrastructure/Resources.scala
+++ b/src/main/scala/main/infrastructure/Resources.scala
@@ -73,5 +73,3 @@ class Resources {
}
}
}
-
-// TODO: add method for viewing threads