kvark / copyless

[deprecated] Avoid memcpy calls when working with standard containers
Apache License 2.0
276 stars 12 forks source link

box! macro? #11

Open glandium opened 5 years ago

glandium commented 5 years ago

It feels like there could be a box! macro that would do Box::alloc().init(...).

kvark commented 5 years ago

There could be, yeah. I have a slight preference of not introducing macros unless necessary.

Speedy37 commented 5 years ago

It looks like creating a Box::new method that use Box::alloc().init() is still copyless: https://rust.godbolt.org/z/GyAohL

There is probably something to be done in std to get the optimization without much troubles.

Edit: just did the same test with Vec, without success.

kvark commented 5 years ago

@Speedy37 we looked at your (interesting!) case and realized that the check for NULL returned by alloc() was missing in the version of code you copied. The fixed version (that is in master and 0.1.4) makes new_fast not feasible any more: https://rust.godbolt.org/z/JgOjcn