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

Make create zero out the new buffer #102

Merged
merged 2 commits into from May 18, 2016
Merged

Conversation

talex5
Copy link
Contributor

@talex5 talex5 commented May 14, 2016

The API should be safe by default. The new create_unsafe function can be used if you want to trade safety for speed.

Fixes #30

See also: mirage/mirage-tcpip#204

let buffer = Bigarray.(Array1.create char c_layout len) in
{ buffer ; len ; off = 0 }

let create len =
let t = create_unsafe len in
Bigarray.Array1.fill t.buffer (Char.chr 0);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we reuse the memset we define ~110 lines below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any benefit? I guess memset is only needed if you want to fill a sub-region of an array (fill can only fill the whole thing, but that's what we want here).

Copy link
Member

Choose a reason for hiding this comment

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

consistency is my argument (I've to keep less symbols in my head when reading the code)

The new `create_unsafe` function can be used if you want to trade safety
for speed.

Fixes mirage#30
@talex5
Copy link
Contributor Author

talex5 commented May 17, 2016

OK, it uses memset now.

@hannesm
Copy link
Member

hannesm commented May 17, 2016

imho good to go (apart from a missing changes entry)! thanks!

@yomimono
Copy link
Contributor

I'm yomimono and I approve this PR.

@talex5 talex5 merged commit 07c6b76 into mirage:master May 18, 2016
hannesm added a commit to hannesm/ocaml-cstruct that referenced this pull request Jul 7, 2017
there's no need to allocate and fill with zero just to blit afterwards.

this is a performance regression which was introduced in mirage#102 (May 2016), when
`create` changed its semantics.
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

Successfully merging this pull request may close these issues.

None yet

3 participants