Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

Idiom #207 Allocate a list that is automatically deallocated

Allocate a list a containing n elements (n assumed to be too large for a stack) that is automatically deallocated when the program exits the scope it is declared in.

let a = vec![0; n];

Heap allocations are deallocated when the variable goes out of scope.
  integer, dimension(:), allocatable :: a
  allocate (a(n))

New implementation...
< >
tkoenig