| 32 | public final class Rosti { |
| 33 | |
| 34 | public static long alloc(ColumnTypes types, long capacity) { |
| 35 | // min capacity that works on all platforms is 16 |
| 36 | assert capacity >= 16; |
| 37 | |
| 38 | final int columnCount = types.getColumnCount(); |
| 39 | final long mem = Unsafe.malloc(4L * columnCount, MemoryTag.NATIVE_ROSTI); |
| 40 | try { |
| 41 | long p = mem; |
| 42 | for (int i = 0; i < columnCount; i++) { |
| 43 | Unsafe.putInt(p, types.getColumnType(i)); |
| 44 | p += Integer.BYTES; |
| 45 | } |
| 46 | // this is not an exact size of memory allocated for Rosti, but this is useful to |
| 47 | // track that we free these maps |
| 48 | long pRosti = alloc(mem, columnCount, Numbers.ceilPow2(capacity) - 1); |
| 49 | if (pRosti != 0) { |
| 50 | Unsafe.recordMemAlloc(getAllocMemory(pRosti), MemoryTag.NATIVE_ROSTI); |
| 51 | } |
| 52 | return pRosti; |
| 53 | } finally { |
| 54 | Unsafe.free(mem, 4L * columnCount, MemoryTag.NATIVE_ROSTI); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | public static native void clear(long pRosti); |
| 59 | |