/** * Allocates native memory, aligned to a minimum boundary. * * @param size The number of bytes to allocate * @param align The minimum alignment of the memory * @param clear Whether the memory should be cleared (zeroed) * @return A new {@link AllocatedDirectMemory} */ static final AllocatedNativeMemory allocateAligned(int size, int align, boolean clear) { long memory = IO.allocateMemory(size + align - 1, clear); if (memory == 0) { throw Py.RuntimeError("failed to allocate " + size + " bytes"); } return new AllocatedNativeMemory(memory, size, align); }
/** * Allocates native memory, aligned to a minimum boundary. * * @param runtime The Ruby runtime * @param size The number of bytes to allocate * @param align The minimum alignment of the memory * @param clear Whether the memory should be cleared (zeroed) * @return A new {@link AllocatedDirectMemoryIO} */ static final AllocatedNativeMemoryIO allocateAligned( Ruby runtime, int size, int align, boolean clear) { long memory = IO.allocateMemory(size + align - 1, clear); return memory != 0 ? new AllocatedNativeMemoryIO(runtime, memory, size, align) : null; }
/** * Allocates native memory * * @param runtime The Ruby runtime * @param size The number of bytes to allocate * @param clear Whether the memory should be cleared (zeroed) * @return A new {@link AllocatedDirectMemoryIO} */ static final AllocatedNativeMemoryIO allocate(Ruby runtime, int size, boolean clear) { long memory = IO.allocateMemory(size, clear); return memory != 0 ? new AllocatedNativeMemoryIO(runtime, memory, size, 1) : null; }