What's the point of static arrays ?
box at mail.com
Fri Jul 10 10:47:49 UTC 2020
On Friday, 10 July 2020 at 10:13:23 UTC, wjoe wrote:
> However stack memory needs to be allocated at program start. I
> don't see a huge benefit in allocation speed vs. heap
> pre-allocation, or is there?
> I mean 1 allocation vs 2 isn't going to noticeably improve
> overall performance.
Allocation on the stack is basically just a single processor
instruction that moves the stack pointer (well, ofc you also need
to initialize array elements). Meanwhile, allocation on the heap
involves much more complex logic of the memory allocator.
Moreover, in D dynamic arrays use GC, thus the memory allocation
may involve the trash collection step.
More information about the Digitalmars-d-learn