You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It can be seen clearly that foo does the allocation first and then runs memset, while bar clearly runs the memset before allocation, and it then memcpy the content into the box.
This is not very optimal. Users should be able to expect Box::new() to have no stack allocation.
It seems that Box::new() is implemented via box-syntax, and it even has #[inline(always)], so they shouldn't really have any difference here...
The text was updated successfully, but these errors were encountered:
If you feed the compiler with the following code:
The compiler would output (from playground) in release mode:
It can be seen clearly that
foo
does the allocation first and then runsmemset
, whilebar
clearly runs thememset
before allocation, and it thenmemcpy
the content into the box.This is not very optimal. Users should be able to expect
Box::new()
to have no stack allocation.It seems that
Box::new()
is implemented viabox
-syntax, and it even has#[inline(always)]
, so they shouldn't really have any difference here...The text was updated successfully, but these errors were encountered: