@kornel@mastodon.social cover
@kornel@mastodon.social avatar

kornel

@kornel@mastodon.social

This profile is from a federated server and may be incomplete. For a complete list of posts, browse on the original instance.

kornel , to random
@kornel@mastodon.social avatar

Who could have guessed that a plastic recycling method promoted by Exxon requires 9 times more new fossil fuels than the amount of plastic it manages to successfully recycle?
And the US allows creative accounting that ends up calling that 100% recycled plastic, by counting byproducts like diesel as "recycled" "plastic".

https://www.propublica.org/article/delusion-advanced-chemical-plastic-recycling-pyrolysis

became_fish , to random
@became_fish@jorts.horse avatar

people say "C++ isn't any closer to the metal than is" but what is the memory footprint of returning a Result? in C++ i can pass an out parameter by reference to avoid allocating anything on the stack - how do i do that in rust? is it with a &mut ptr? is it done automatically by the compiler when returning?

kornel ,
@kornel@mastodon.social avatar

@became_fish Yes, the ABI automatically switches to returning by reference when the Result is too large to spread across registers.
There's also niche optimization, e.g. Result<Box<T>, UnitErr> is just a pointer. More efficient than ABIs of unique_ptr/variant/expected.

kornel ,
@kornel@mastodon.social avatar

@became_fish &str is conceptually identical to string_view.
Box<str> is the same ptr+len, but heap allocated.
Vec<char> is UTF-32, and generally avoided.
Rust has no copy constructors. You can't copy heap types by mistake. It's like RVO guaranteed everywhere all the time.

kornel ,
@kornel@mastodon.social avatar
kornel ,
@kornel@mastodon.social avatar

@became_fish Yes, because String is heap allocated by definition. It's {ptr, capacity, len}.

&str is ambivalent about the data source, and guarantees to never run any destructor or free() on the pointer.

Cow<str> holds a bool that tracks whether to free or not.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • test
  • worldmews
  • mews
  • All magazines