3 ms·
The stack is not some magical location in RAM that is faster, and in any case you can have a pointer to the stack. It's super common to define a struct on the
by _3u10 3y ago
The stack is not some magical location in RAM that is faster, and in any case you can have a pointer to the stack.
It's super common to define a struct on the stack and then pass a pointer to an init function to initialize the value that is on the stack.
Sometimes pointers are faster because you don't have to copy the entire struct.
What largely determines the performance of values vs. pointers is whether that location in RAM is cached, and whether you need to allocate memory on the heap.