Skip to content

Instantly share code, notes, and snippets.

View s4hubhamp's full-sized avatar
🎶

Shubham Pawar s4hubhamp

🎶
View GitHub Profile
@s4hubhamp
s4hubhamp / .zig
Created April 2, 2025 10:08
Alignments in Zig
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,
@s4hubhamp
s4hubhamp / main.rs
Last active March 5, 2025 07:22
Rust Boxes and Cells
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