xpenatan / gdx-teavm

Run Libgdx in a webbrowser with teavm
Apache License 2.0
108 stars 16 forks source link

Feature Request: Implementation of missing BufferUtils methods #134

Open McMurat opened 3 hours ago

McMurat commented 3 hours ago

Hello, to get my project running I need the following methods implemented in com.badlogic.gdx.utils.BufferUtils:

disposeUnsafeByteBuffer
newUnsafeByteBuffer
getAllocatedBytesUnsafe

This should be straightforward. The result of getAllocatedBytesUnsafecan be 0, disposeUnsafeByteBuffera no-op and newUnsafeByteBuffercan forward to newByteBuffer. Thank you.

xpenatan commented 2 hours ago

Hey, I don't have examples using unsafe, can you create one with the expected output results?

All these methods are basically just adding it to a static array list if you look at the source code. In javascript everything is Int8Array or other types so freeMemory dont exist.

McMurat commented 2 hours ago

They do not need to be actually unsafe (that's obviously not possible in the web). It's enough to just forward the newUnsafeByteBuffer to the existing newByteBuffer implementation and treat the other two functions I mentioned as no ops. This will make existing code work. This whole unsafe thing is only for extra performance and does not add any functionality to the buffer.