Memory allocations

Hi Lucas!
The number returned by @allocated actually corresponds to the number of bytes allocated on the “heap”, as opposed to the “stack”. Roughly speaking, Julia allocates immutable objects (like integers) on the stack, which is very fast, but mutable objects (like vectors) on the heap, which is much slower.
When we want to optimize the performance of a code, usually we seek to reduce heap allocations, and that is why @allocated focuses on those.

9 Likes