use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class MallocTests method withMap.
@Test
public void withMap() {
ConcurrentMap<Long, Pointer> map = new MapMaker().concurrencyLevel(4).initialCapacity(500000).makeMap();
String str = "This is the string to store into the off-heap memory";
int size = str.length();
int howMany = 1000000;
byte[] payload = str.getBytes();
logger.info("adding " + howMany + " strings of " + size + " bytes...");
for (long i = 0; i < howMany; i++) {
Pointer p = mem.store(payload);
map.put(i, p);
}
logger.info("...done");
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class MallocTests method oneMillionEntriesWithRead.
@Test
public void oneMillionEntriesWithRead() {
logger.info("total capacity=" + Ram.inMb(mem.capacity()));
assertNotNull(mem);
int size = 400;
int howMany = 1000000;
logger.info("payload size=" + Ram.inKb(size));
logger.info("entries=" + howMany);
String test = "this is a nicely crafted test";
byte[] payload = test.getBytes();
for (int i = 0; i < howMany; i++) {
Pointer p = mem.store(payload);
byte[] check = mem.retrieve(p);
assertNotNull(check);
assertEquals(test, new String(check));
}
logger.info("total used=" + Ram.inMb(mem.used()));
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class MemoryManagerTests method smokeTest.
@Test
public void smokeTest() {
Random rnd = new Random();
int size = rnd.nextInt(10) * (int) MemoryManager.capacity() / 100;
logger.info("payload size=" + Ram.inKb(size));
Pointer p = MemoryManager.store(new byte[size]);
logger.info("stored");
assertNotNull(p);
assertEquals(size, p.end);
assertEquals(size, MemoryManager.activeBuffer.used());
MemoryManager.free(p);
assertEquals(0, MemoryManager.activeBuffer.used());
logger.info("end");
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class MemoryManagerTests method readTest.
@Test
public void readTest() {
for (OffHeapMemoryBuffer buffer : MemoryManager.buffers) {
for (Pointer ptr : buffer.pointers) {
if (!ptr.free) {
byte[] res = MemoryManager.retrieve(ptr);
assertNotNull(res);
assertEquals(new String(payload), new String(res));
}
}
}
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class ConcurrentTests2 method get.
private void get(String key) {
Pointer p = map.get(key);
read.incrementAndGet();
if (p != null) {
got.incrementAndGet();
byte[] payload = MemoryManager.retrieve(p);
if (key.equals(new String(payload)))
good.incrementAndGet();
else
bad.incrementAndGet();
} else {
missed.incrementAndGet();
}
}
Aggregations