logoalt Hacker News

fancyfredbot • yesterday at 8:12 PM • 1 reply • view on HN

What happens if the memory is freed in a different order to allocation? Does the language disallow that? Or does it get allowed but mean the stack can't shrink?

How are you deciding how many stacks to use?


Replies

Aardappel • yesterday at 8:16 PM

The compiler automatically optimally allocates all arrays currently in scope that are able to grow to "stacks" (address spaced reserved areas).

The programmer choose what to store where, so you typically store things in arrays by lifetime. Goose gives you many more tools to do that, it can store entire variable sized trees of an enum type in a single array.

You try to avoid having to deallocate in mixed/random order, but if you absolutely must, you can turn arrays into pools, basically.

➕ show 1 reply