What's the point of static arrays ?
nise at nise.com
Thu Jul 9 19:06:09 UTC 2020
On Thursday, 9 July 2020 at 18:51:47 UTC, Paul Backus wrote:
> Note that using VLAs in C is widely considered to be bad
> practice, and that they were made optional in the C11 standard.
> If you want to allocate an array on the stack, the best way is
> to use a static array for size below a predetermined limit, and
> fall back to heap allocation if that limit is exceeded. An easy
> way to do this in D is with
I know but I at least really like them because they solve a few
obstacles for me. If you have a maximum allowed size, then they
should be alright but opinions differ here.
I do not recommend allocating a 'max' static size if you don't
use just a fraction of it. The reason is that will possibly break
out more stack pages than necessary leading to unnecessary memory
consumption, especially if you initialize the entire array. This
is another reason I like VLAs.
More information about the Digitalmars-d-learn