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

of_sub_string etc #200

Closed
cfcs opened this issue Jan 20, 2018 · 3 comments
Closed

of_sub_string etc #200

cfcs opened this issue Jan 20, 2018 · 3 comments

Comments

@cfcs
Copy link

cfcs commented Jan 20, 2018

We currently have these functions for initializing a new Cstruct:

  val Cstruct.of_bigarray ?off:int -> ?len:int -> buffer -> t

and

  val Cstruct.of_string ?allocator:(int -> t) -> string -> t
  val Cstruct.of_bytes ?allocator:(int -> t) -> bytes -> t
  val Cstruct.of_hex string -> t

It would be nice, and would seem more consistent, if it would be possible to construct a Cstruct.t directly from a slice of a string/bytes (like you can with of_bigarray) instead of having to first do a String.sub/Bytes.sub (which means a redundant memcpy operation) before the copy into the new Cstruct.t.

Also, why is there no ?allocator for of_bigarray? Is that because it doesn't actually copy, but maps to the same memory? If so, that should probably be documented?

@XVilka
Copy link
Contributor

XVilka commented Jan 9, 2019

@cfcs slicing was added, can this one be closed then?

@cfcs
Copy link
Author

cfcs commented Jan 9, 2019

Yes, thanks!

@cfcs cfcs closed this as completed Jan 9, 2019
@cfcs
Copy link
Author

cfcs commented Jan 9, 2019

(I guess the ?allocator question is still relevant, but I have forgotten why I cared when I reported this)

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

2 participants