While learning “15.3. Running Code on Cleanup with the Drop Trait” of the Rust official book, I just wondered the memory layout of Rust program.
TL;DR: Currently the default global allocator is unspecified. Libraries, however, like cdylibs and staticlibs are guaranteed to use the System by default.
Struct std::alloc::System:
The default memory allocator provided by the operating system. This is based on malloc on Unix platforms and HeapAlloc on Windows, plus related functions.
I tried to implement LWE with Rust. Here is the memo about linear algebra libraries.
Which library to use As of Nov.2021, there was no “defacto standard” linear algebra library in Rust. I investigated, and decided to use ndarray or nlagebra.
ndarray vs nalgebra - Reddit
ndarray https://github.com/rust-ndarray/ndarray
tensorflow/Rust uses ndarray.
ndarray is mentioned in Rust cookbook: ndarray use BLAS impelementation on the runtime (Intel MKL, OpenBLAS, etc.), so it could be faster than other libraries.
Serde (serializing and deserializing) is one of the most frequently used library in Rust.
The library is production ready, usually used with Serde JSON (because of the popularity of REST APIs).
Serialization From Wikipedia, In computing, serialization is the process of translating a data structure or object state into a format that can be stored (for example, in a file or memory data buffer) or transmitted (for example, over a computer network) and reconstructed later (possibly in a different computer environment)
Disclamer The implementations in this post have a lot of room for improvement. As of Apr. 2021, they are more like code monkey’s code :(
Reverse a string fn main() { let s1 = String::from("Please reverse me with spaces!日本語.한국어"); println!("Original string: {}",s1); let mut s2 = String::from(""); for c in s1.chars().rev() { s2.push(c); } println!("Reversed: {}",s2); } In Rust, both String and a string slice &str are UTF-8 encoded.
chars() returns an iterator over chars of a string slice.
Tutorial The URL I followed.
https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm
Pre-requirement You should install npm beforehand. To compile wasm-pack, apt install -y build-essential and install gcc. In case of Ubuntu, apt install -y libssl-dev pkg-config. Download wasm-pack To build the package, we need an additional tool, wasm-pack. This helps compile the code to WebAssembly, as well as produce the right packaging for npm.
cargo install wasm-pack Write codes cargo new --lib hello-wasm cd hello-wasm src/lib.
Official document.
WSL (Nov, 2020) In my environment (Windows Subsystem Linux), I could install as follows.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >1 echo "export PATH=$HOME/.cargo/bin:$PATH " >> ~/.bashrc CentOS8 CentOS 8 in GCP. Basically same, but just for a memo.
curl -sSf https://sh.rustup.rs | sh When memory allocation failed, try to set up RUSTUP_UMPACK_RAM.
https://github.com/rust-lang/rustup/issues/2128
Update Rust If you install Rust in this way, you can update your Rust by the command below: