Practical guides on no_std and wasm support

Using the default allocator costs less than 8k with LTO after stripping debuginfo. I don't see a point in trying to use a lighter allocator, especially when any smaller memory allocator almost certainly increases memory usage due to increased fragmentation.

#[no_mangle]
pub fn foo() -> *mut u8 {
    Box::into_raw(Box::new(1))
}
#[no_mangle]
pub fn drop(a: *mut u8) {
    unsafe { Box::from_raw(a); }
}
$ rustc example.rs --target wasm32-unknown-unknown --crate-type cdylib -Copt-level=3 -Clto -Cstrip=debuginfo
$ ls -l
-rwxr-xr-x 1 bjorn3 bjorn3 7892  1 jan  1970 example.wasm
2 Likes