Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be a Native IoBuffer constructor public #8

Closed
SalomonBrys opened this issue Sep 4, 2018 · 3 comments
Closed

There should be a Native IoBuffer constructor public #8

SalomonBrys opened this issue Sep 4, 2018 · 3 comments

Comments

@SalomonBrys
Copy link
Contributor

What if we want an IoBuffer to use as memory backend a specific CPointer ?
There are a lot of use cases for this:

  • Manual allocation of a specific known size
  • Read from a pointer received from a C/C++ library
  • etc.

I suggest the following addtion to the Native IoBuffer class:

constructor(content: CPointer<ByteVar>, contentCapacity: Int) : this(content, contentCapacity, null)

Of course, the memory management of the CPointer's memory is the programmer's repsonsability.
This could be emphasized by using a companion object method instead of a constructor:

companion object {
    fun makeView(content: CPointer<ByteVar>, contentCapacity: Int) = IoBuffer(content, contentCapacity, null)
}
@cy6erGn0m
Copy link
Contributor

First of all, one shouldn't allocate IoBuffer directly. A packet should be used instead in most cases. It's not clear for me whether it should be ByteReadPacket.viewOf(pointer, size) or IoBuffer.viewOf(pointer, size). For now I am thinking of the first option. The only case for the second is very specific performance critical corners.

CPointers were disabled due to iOS related issues with K/N compiler but should be enabled back soon.

@SalomonBrys
Copy link
Contributor Author

I disagree,
IoBuffer is very usefull to write.

While ByteReadPacket.viewOf(pointer, size) can be used to read, it could not be used to write on the memory of the Cpointer, which is why I think IoBuffer.viewOf(pointer, size) is very needed.

@fzhinkin
Copy link
Collaborator

We're rebooting the kotlinx-io development (see #131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants