This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn main() !void { | |
// Alignment in computer programming refers to the way data is arranged and accessed in memory. | |
// It is a rule that specifies the memory address boundaries at which a data type or variable | |
// should be stored. | |
// The goal of alignment is to ensure that memory accesses are efficient and that the processor | |
// can retrieve data in the most optimized way. | |
// https://ziggit.dev/t/whats-up-with-alignof-u128/1271/3?u=s4hubhamp | |
// Definition as per Zig docs | |
// Each type has an alignment - a number of bytes such that, when a value of the type is loaded from or stored to memory, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::rc::Rc; | |
use std::cell::{Cell, RefCell}; | |
use std::ops::Deref; | |
fn boxes() { | |
// Box allows mutable and immutable borrows to a variable. It's just a pointer to data on a heap | |
// Box returns ownership of the passed value. So if passed value does not implement clone then value gets moved. | |
let a = Box::new(1); // a is a Box pointing to an integer on the heap | |
let b = &a; // b is a reference to the Box |