Hacker News new | ask | show | jobs
by nullc 1911 days ago
You're allocating a megabyte on the stack?

Does rust have compile time protection against stack overflow? (... and what about recursion? is the stack dynamically resized at runtime?)

2 comments

I'm allocating a megabyte inline. I can put the containing struct on the heap if I need to (I may be doing that; can't remember), but I don't want that to be the concern of the struct itself.

For example: what if I decide at some point to create a Vec of this struct? I don't want each of those elements then also putting their internal buffers into separate allocations on the heap, when the Vec itself is already on the heap. I want the struct to be as "flat" as possible, and to only allocate for the sake of the stack as a final step when the use-case demands it

We do not, runtime mitigation only (stack probes).

Recursion can blow your stack.