Great visualizations make it so easy to understand.
@michaelscofield45245 ай бұрын
This and your past series are by far some of the best Zig and general programming content on the internet, really learned a lot by watching. Keep it up!
@deadmarshalАй бұрын
Hey. Please consider making a video on multi-dimensional arrays and slices and different methods of passing them to functions as I'm having difficulty understanding these. Thanks a lot!
@dudethebuilderАй бұрын
Great idea! I'll put it on schedule for upcoming videos.
@thilina912 ай бұрын
thanks for the video!! great stuff!
@joaquimpedro49847 күн бұрын
I have a doubt, if we try to allocate a constant u32 (4bytes) in the heap it also create a u32in the statict block, or just a u8 (it only stores the address of the heap). This question makes sense or just reveal that i don't understood nothing!
@dudethebuilder7 күн бұрын
You're right, that question is very valid and goes to the core of how Zig handles allocations. The allocation is in the heap area of memory but the actual pointer you get back is either in the static (const) or stack (var) area. The pointer is the size of a usize, i.e. 8 bytes in 64 bit systems.
@zomaarwat95 ай бұрын
If the const in the function gets stored in static memory will it outlive its scope or does something invalidate it after the function ends?
@dudethebuilder5 ай бұрын
Great question. It will outlive the scope of the function. In the next video, I'll show some code demonstrating this.
@joaquimpedro4984Ай бұрын
If it lives in the static block, all the other functions will have access to it?
@fizzbuzz48205 ай бұрын
Since const values are pretty far away from the stack frame, doesn't it affect execution time due to weaker data locality?
@dudethebuilder5 ай бұрын
I think that could happen if we were dealing with large amounts of data where reading a contiguous chunk into a cache line is desired. But usually, function parameters are small enough to place into CPU registers directly, and Zig also performs what it calls Parameter Reference Optimization (PRO) that automatically determines whether it's more efficient to pass a const pointer to large data instead of copying the data itself. In this case too the pointer would fit in a register.
@andreffrosa5 ай бұрын
What about const parameters?
@dudethebuilder5 ай бұрын
In Zig, function parameters are always const, but they're still allocated in the function's stack frame; probably since they have different values in each call. But to actually mutate a value passed to a function, you have to pass a pointer to it in Zig.