You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue here is that this call will give you a pointer to only the writable bytes that actually exist in your ByteBuffer. If there are only 2 bytes, or even 0 bytes, that's all you're going to get. That can make using this API extremely tricky, and requires calls to the (very flawed, see #537) function changeCapacity before using it.
It'd be nice to have a function like ByteBuffer.writeWithUnsafeMutableBytes(minimumWritableSpace: Int, _ block: (UnsafeMutableRawBufferPointer) -> Int). This function would guarantee that the minimum size of the pointer in the block would be appropriately set, performing any CoW or other operation as needed.
This is not a trivial patch, but if you're interested in the internals of ByteBuffer this would be a good thing to build.
The text was updated successfully, but these errors were encountered:
The Problem
Plenty of C APIs expose APIs where they write into a buffer provided by the caller. For example, consider OpenSSL's
SSL_read
, declared like this:In this model, OpenSSL will write into the pointer at
buf
. To support this withByteBuffer
, the following code has to be written:The issue here is that this call will give you a pointer to only the writable bytes that actually exist in your
ByteBuffer
. If there are only 2 bytes, or even 0 bytes, that's all you're going to get. That can make using this API extremely tricky, and requires calls to the (very flawed, see #537) functionchangeCapacity
before using it.It'd be nice to have a function like
ByteBuffer.writeWithUnsafeMutableBytes(minimumWritableSpace: Int, _ block: (UnsafeMutableRawBufferPointer) -> Int)
. This function would guarantee that the minimum size of the pointer in the block would be appropriately set, performing any CoW or other operation as needed.This is not a trivial patch, but if you're interested in the internals of
ByteBuffer
this would be a good thing to build.The text was updated successfully, but these errors were encountered: