@Override public ByteBuffer allocate(final int size) { final Long address = MemoryUtil.nmemAlloc(size); final ByteBuffer byteBuffer = MemoryUtil.memByteBuffer(address, size); DEALLOCATORS.put(address, createDeallocator(address, byteBuffer)); return byteBuffer; }
/** * Converts the specified {@link STBIWriteCallback} arguments to a ByteBuffer. * * <p>This method may only be used inside a STBIWriteCallback invocation.</p> * * @param data the STBIWriteCallback {@code data} argument * @param size the STBIWriteCallback {@code size} argument * * @return the data as a ByteBuffer */ public static ByteBuffer getData(long data, int size) { return memByteBuffer(data, size); }
/** * Converts the specified {@link STBIReadCallback} arguments to a ByteBuffer. * * <p>This method may only be used inside a STBIReadCallback invocation.</p> * * @param data the STBIReadCallback {@code data} argument * @param size the STBIReadCallback {@code size} argument * * @return the data as a ByteBuffer */ public static ByteBuffer getData(long data, int size) { return memByteBuffer(data, size); }
/** Unsafe version of {@link #DeviceName}. */ public static ByteBuffer nDeviceName(long struct) { return memByteBuffer(struct + DISPLAY_DEVICE.DEVICENAME, 32 * 2); } /** Unsafe version of {@link #DeviceNameString}. */
/** Unsafe version of {@link #DeviceID}. */ public static ByteBuffer nDeviceID(long struct) { return memByteBuffer(struct + DISPLAY_DEVICE.DEVICEID, 128 * 2); } /** Unsafe version of {@link #DeviceIDString}. */
/** Unsafe version of {@link #dmFormName}. */ public static ByteBuffer ndmFormName(long struct) { return memByteBuffer(struct + DEVMODE.DMFORMNAME, 32 * 2); } /** Unsafe version of {@link #dmFormNameString}. */
/** Unsafe version of {@link #DeviceString}. */ public static ByteBuffer nDeviceString(long struct) { return memByteBuffer(struct + DISPLAY_DEVICE.DEVICESTRING, 128 * 2); } /** Unsafe version of {@link #DeviceStringString}. */
/** Unsafe version of {@link #pipelineCacheUUID}. */ public static ByteBuffer npipelineCacheUUID(long struct) { return memByteBuffer(struct + VkPhysicalDeviceProperties.PIPELINECACHEUUID, VK_UUID_SIZE); } /** Unsafe version of {@link #pipelineCacheUUID(int) pipelineCacheUUID}. */
/** Unsafe version of {@link #driverUUID}. */ public static ByteBuffer ndriverUUID(long struct) { return memByteBuffer(struct + VkPhysicalDeviceIDProperties.DRIVERUUID, VK_UUID_SIZE); } /** Unsafe version of {@link #driverUUID(int) driverUUID}. */
/** @see MemoryUtil#memUTF8(ByteBuffer, int, int) */ static String decodeUTF8(long source, int length) { if (length <= 0) { return ""; } byte[] bytes = length <= ARRAY_TLC_SIZE ? ARRAY_TLC_BYTE.get() : new byte[length]; memByteBuffer(source, length).get(bytes, 0, length); return new String(bytes, 0, length, StandardCharsets.UTF_8); }
/** Like {@link #memByteBufferNT1(long, int) memByteBufferNT1}, but returns {@code null} if {@code address} is {@link #NULL}. */ @Nullable public static ByteBuffer memByteBufferNT1Safe(long address, int maxLength) { return address == NULL ? null : memByteBuffer(address, memLengthNT1(address, maxLength)); }
/** Like {@link #memByteBufferNT1(long) memByteBufferNT1}, but returns {@code null} if {@code address} is {@link #NULL}. */ @Nullable public static ByteBuffer memByteBufferNT1Safe(long address) { return address == NULL ? null : memByteBuffer(address, memLengthNT1(address, Integer.MAX_VALUE)); }
/** * Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a {@link ByteBuffer} instance that * starts at the pointer address and has capacity equal to the specified {@code size}. * * @throws BufferUnderflowException If the buffer's current position is not smaller than its limit */ public ByteBuffer getByteBuffer(int size) { return memByteBuffer(get(), size); }
/** * Converts the specified {@link GLDebugMessageARBCallback} arguments to a String. * * <p>This method may only be used inside a GLDebugMessageARBCallback invocation.</p> * * @param length the GLDebugMessageARBCallback {@code length} argument * @param message the GLDebugMessageARBCallback {@code message} argument * * @return the message as a String */ public static String getMessage(int length, long message) { return memUTF8(memByteBuffer(message, length)); }
/** * Converts the specified {@link GLDebugMessageCallback} arguments to a String. * * <p>This method may only be used inside a GLDebugMessageCallback invocation.</p> * * @param length the GLDebugMessageCallback {@code length} argument * @param message the GLDebugMessageCallback {@code message} argument * * @return the message as a String */ public static String getMessage(int length, long message) { return memUTF8(memByteBuffer(message, length)); }
/** * Converts the specified {@link GLDebugMessageCallback} arguments to a String. * * <p>This method may only be used inside a GLDebugMessageCallback invocation.</p> * * @param length the GLDebugMessageCallback {@code length} argument * @param message the GLDebugMessageCallback {@code message} argument * * @return the message as a String */ public static String getMessage(int length, long message) { return memUTF8(memByteBuffer(message, length)); }
/** * Creates a new direct ByteBuffer that starts at the specified memory address and has capacity equal to the null-terminated string starting at that * address. A single \0 character will terminate the string. The returned buffer will NOT include the \0 byte. * * <p>This method is useful for reading ASCII and UTF8 encoded text.</p> * * @param address the starting memory address * * @return the new ByteBuffer */ public static ByteBuffer memByteBufferNT1(long address) { return memByteBuffer(address, memLengthNT1(address, Integer.MAX_VALUE)); }
/** * Converts the specified {@link GLDebugMessageAMDCallback} arguments to a String. * * <p>This method may only be used inside a GLDebugMessageAMDCallback invocation.</p> * * @param length the GLDebugMessageAMDCallback {@code length} argument * @param message the GLDebugMessageAMDCallback {@code message} argument * * @return the message as a String */ public static String getMessage(int length, long message) { return memUTF8(memByteBuffer(message, length)); }
/** Unsafe version of {@link #pixels(int) pixels}. */ public static ByteBuffer npixels(long struct, int capacity) { return memByteBuffer(memGetAddress(struct + STBTTPackContext.PIXELS), capacity); } /** Unsafe version of {@link #nodes}. */
@Override public ByteBuffer allocate(final int size) { final Long address = MemoryUtil.nmemAlloc(size); final ByteBuffer byteBuffer = MemoryUtil.memByteBuffer(address, size); DEALLOCATORS.put(address, createDeallocator(address, byteBuffer)); return byteBuffer; }