4 ms·
It sounds incredibly dangerous in the hands of a usual go programmer who has no idea what the difference between the stack and the heap is.
by brabel 3mo ago
It sounds incredibly dangerous in the hands of a usual go programmer who has no idea what the difference between the stack and the heap is.
- nixon_why69 3mo agoBeen a while since I used go but I remember it being kind of uniquely hard to tell? Like a struct is on the stack, but a *struct is maybe on the heap, depending on escape analysis?
- DanielHB 3mo agoisn't it the exact same as C in this regard? The pointer being on the stack or not depends how it was originally allocated.
- nixon_why69 3mo agoIn C you explicitly malloc things onto the heap. In go, taking the address of something maybe allocates on the heap, or maybe not if escape analysis can keep it on the stack.
- brabel 3mo agoIn go you don’t need to care, the GC will take care of allocations on the heap and the runtime will choose when something should go on the stack. That’s the problem: in this other language it’s suicidal to program as if it was the same as Go as you will just make huge mistakes like returning a pointer to a local variable.