MCPcopy Create free account
hub / github.com/ReadyTalk/avian / unsafeMemory

Method unsafeMemory

test/UnsafeTest.java:23–77  ·  view source on GitHub ↗
(Unsafe u)

Source from the content-addressed store, hash-verified

21 }
22
23 private static void unsafeMemory(Unsafe u) {
24 final long size = 64;
25 long memory = u.allocateMemory(size);
26 try {
27 for (int i = 0; i < size; ++i)
28 u.putByte(memory + i, (byte) 42);
29
30 for (int i = 0; i < size; ++i)
31 expect(u.getByte(memory + i) == 42);
32
33 for (int i = 0; i < size / 2; ++i)
34 u.putShort(memory + (i * 2), (short) -12345);
35
36 for (int i = 0; i < size / 2; ++i)
37 expect(u.getShort(memory + (i * 2)) == -12345);
38
39 for (int i = 0; i < size / 2; ++i)
40 u.putChar(memory + (i * 2), (char) 23456);
41
42 for (int i = 0; i < size / 2; ++i)
43 expect(u.getChar(memory + (i * 2)) == 23456);
44
45 for (int i = 0; i < size / 4; ++i)
46 u.putInt(memory + (i * 4), 0x12345678);
47
48 for (int i = 0; i < size / 4; ++i)
49 expect(u.getInt(memory + (i * 4)) == 0x12345678);
50
51 for (int i = 0; i < size / 4; ++i)
52 u.putFloat(memory + (i * 4), 1.2345678F);
53
54 for (int i = 0; i < size / 4; ++i)
55 expect(u.getFloat(memory + (i * 4)) == 1.2345678F);
56
57 for (int i = 0; i < size / 8; ++i)
58 u.putLong(memory + (i * 8), 0x1234567890ABCDEFL);
59
60 for (int i = 0; i < size / 8; ++i)
61 expect(u.getLong(memory + (i * 8)) == 0x1234567890ABCDEFL);
62
63 for (int i = 0; i < size / 8; ++i)
64 u.putDouble(memory + (i * 8), 1.23456789012345D);
65
66 for (int i = 0; i < size / 8; ++i)
67 expect(u.getDouble(memory + (i * 8)) == 1.23456789012345D);
68
69 for (int i = 0; i < size / 8; ++i)
70 u.putAddress(memory + (i * 8), 0x12345678);
71
72 for (int i = 0; i < size / 8; ++i)
73 expect(u.getAddress(memory + (i * 8)) == 0x12345678);
74 } finally {
75 u.freeMemory(memory);
76 }
77 }
78
79 private static void unsafeArray(Unsafe u) {
80 final int offset = u.arrayBaseOffset(long[].class);

Callers 1

mainMethod · 0.95

Calls 15

expectMethod · 0.95
allocateMemoryMethod · 0.80
putByteMethod · 0.80
putCharMethod · 0.80
putFloatMethod · 0.80
putDoubleMethod · 0.80
putAddressMethod · 0.80
getByteMethod · 0.45
putShortMethod · 0.45
getShortMethod · 0.45
getCharMethod · 0.45
putIntMethod · 0.45

Tested by

no test coverage detected