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

More garbage friendly cstruct wrapper #214

Merged
merged 1 commit into from Mar 4, 2024
Merged

More garbage friendly cstruct wrapper #214

merged 1 commit into from Mar 4, 2024

Conversation

reynir
Copy link
Contributor

@reynir reynir commented Mar 1, 2024

This supercedes #213. This adds a module Cstruct_ext with functions append_nocopy that does not copy if either argument is empty, and sub and shift variants that return Cstruct.empty instead of the result of Cstruct.sub or Cstruct.shift if the result is empty. The reason for this is an empty cstruct still keeps a live reference to its underlying bigarray.

@reynir reynir merged commit 52f093e into main Mar 4, 2024
5 checks passed
@reynir reynir deleted the cstruct-ext branch March 4, 2024 09:44

(* If we append the empty cstruct and we don't need a fresh copy we can do
nothing. This has different semantics than Cstruct.append. *)
let append_nocopy cs cs' =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm hmm, the name is a bit misleading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it can't avoid copying in all cases. How about append' then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, append' sounds good - or "append_avoid_copy_if_empty"? I'd be interested to upstream this into the Cstruct library, but then it modifies the semantics (that some may rely on, esp. in a concurrent setting), and also I try to remove Cstruct from packages ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they might be interesting to upstream. The append alternative would have to have a different name due to differing semantics that might matter in some cases. Then again as you say we probably want to use cstruct less.

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

Successfully merging this pull request may close these issues.

None yet

2 participants