use of org.directmemory.memory.OffHeapMemoryBuffer 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.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.
the class Starter method rawInsert.
public void rawInsert(int megabytes, int howMany) {
OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(megabytes * 1024 * 1024);
assertNotNull(mem);
int size = mem.capacity() / (howMany);
size -= size / 100 * 1;
logger.info("payload size=" + size);
logger.info("entries=" + howMany);
logger.info("starting...");
long start = System.currentTimeMillis();
byte[] payload = new byte[size];
for (int i = 0; i < howMany; i++) {
mem.store(payload);
}
logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs.");
logger.info("---------------------------------");
dump(mem);
}
use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.
the class Starter method rawInsertMultipleBuffers.
public void rawInsertMultipleBuffers(int buffers, int megabytes, int howMany) {
MemoryManager.init(buffers, Ram.Mb(megabytes));
int size = (int) (MemoryManager.capacity() / (howMany));
size -= size / 100 * 1;
logger.info("payload size=" + size);
logger.info("entries=" + howMany);
logger.info("starting...");
long start = System.currentTimeMillis();
byte[] payload = new byte[size];
for (int i = 0; i < howMany; i++) {
MemoryManager.store(payload);
}
logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs.");
logger.info("---------------------------------");
for (OffHeapMemoryBuffer buf : MemoryManager.buffers) {
dump(buf);
}
}
use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.
the class ConcurrentTests3 method dump.
@AfterClass
public static void dump() {
for (OffHeapMemoryBuffer mem : MemoryManager.buffers) {
dump(mem);
}
logger.info("************************************************");
logger.info("entries: " + entries);
logger.info("inserted: " + map.size());
logger.info("reads: " + read);
logger.info("count: " + count);
logger.info("got: " + got);
logger.info("missed: " + missed);
logger.info("good: " + good);
logger.info("bad: " + bad);
logger.info("disposals: " + disposals);
logger.info("************************************************");
}
use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.
the class BaseTests method smokeTest.
@Test
public void smokeTest() {
OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(1 * 1024 * 1024);
logger.info("buffer size=" + mem.capacity());
assertNotNull(mem);
Random rnd = new Random();
int size = rnd.nextInt(10) * mem.capacity() / 100;
logger.info("size=" + size);
Pointer p = mem.store(new byte[size]);
assertNotNull(p);
assertEquals(size, p.end);
assertEquals(size, mem.used());
mem.free(p);
assertEquals(0, mem.used());
}
Aggregations