static arrays are welcomed in C, where calls to (slow) alloc were diverted to the extreme due to memory leaks (when you forgot to free the allocated array), double free (as a result ...), dangling pointers (all the dangers of manual memory management that can be avoided with GC)
this meant that constructions such as
int foo(char* inp){ char[80] buff; strcpy(inp,buff);
were distributed instead of alloc / free calls, where you need to make sure that everything you allocated was released exactly once during the program
technically, you CAN dynamically allocate on the stack (using the assembly, if you want), however, this can cause some problems with the code, since the length will be known only at runtime and will reduce the possible optimization that the compiler can apply (expand iteration over it, for example)
static arrays are mainly used for buffers due to fast stack allocation
ubyte[1024] buff=void;
they can implicitly convert to an array slice (or explicitly using the slice [] operator), so you can use them almost interchangeably with normal dynamic arrays
source share