#How to create a stack
1 messages · Page 1 of 1 (latest)
std.ArrayList
ArrayListAligned lets you choose the alignment of the items within, ArrayList is an ArrayListAligned with the alignment being the natural alignment of the type
i dont understand can u explain with example?
If you dont know what alignment is, you definitely dont need an ArraylisAligned
In general its very niche
If you want to know, id recommend reading: https://en.m.wikipedia.org/wiki/Data_structure_alignment
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of three separate but related issues: data alignment, data structure padding, and packing.
The CPU in modern computer hardware performs reads and writes to memory most efficiently when the data is naturally aligned, which generally means that the da...
alignment being how much space do i need to go forward to get other element?
Same way
std.ArraylistAligned(u8, alignment_here)
ok
@spiral field So for our own data structures we need an alignment right to get next element we need to skip size of our struct ?
I like this one for explaining alignment https://developer.ibm.com/articles/pa-dalign/
IBM Developer is your one-stop location for getting hands-on training and learning in-demand skills on relevant technologies such as generative AI, data science, AI, and open source.
Interesting
Wikipedia is kinda my go to but that might be better i havent read it
But in C/C++ we dont talk about alignment right? Does it automatically manages the alignment?
Depending on what you do in C/C++, you sometimes do talk about alignment
For many use-cases, it's handled for you, like in std.ArrayList
ok
It manages it for you the same amount as zig does (natural alignment by default)
But the few times you do need to specify alignment manually, zig makes it much easier for you to do so since its part of the type and std is built around it