static final MemoryPointer allocate(Ruby runtime, int typeSize, int count, boolean clear) {
final int total = typeSize * count;
AllocatedDirectMemoryIO io = Factory.getInstance().allocateDirectMemory(runtime, total > 0 ? total : 1, clear);
if (io == null) {
throw new RaiseException(runtime, runtime.getNoMemoryError(),
String.format("Failed to allocate %d objects of %d bytes", typeSize, count), true);
}
return new MemoryPointer(runtime, runtime.fastGetModule("FFI").fastGetClass("MemoryPointer"), io, total, typeSize);
}