| ▲ | noelwelsh 20 hours ago | |
I think there are several advantages of stack allocation: * freeing stack allocated memory is O(1) with a small constant factor: simply set the stack pointer to a new location. In a generational garbage collector, like OCaml, minor garbage collection is O(amount of retained memory) with a larger constant factor. * judiciously stack allocating memory can improve data locality. * unboxed data takes up less space, again improving locality. Overall, I think this about improving constant factors---which makes a big difference in practice! | ||