3 ms·
Can't say for sure if it's the reason in this particular situation, but that would require dynamic memory allocation, and while it may seem backwards to reserve
by TonyTrapp 6y ago
Can't say for sure if it's the reason in this particular situation, but that would require dynamic memory allocation, and while it may seem backwards to reserve more memory than potentially needed on old memory-constrained systems, it is a pattern you see very frequently because on those systems, you actually know exactly how much memory you have. As a result, you know exactly how much memory you can "waste".
Especially on single-tasking systems, it doesn't matter how much memory you waste, because no other program is affected by it.
Or in other words: If you know you are guaranteed to have x KB of memory available and no other program can steal it, and you know that you don't need more than y KB, then why allocate up to y KB dynamically when you can just straight-up allocate y KB statically, which is less work?
- swiley 6y agoIMO the way C programmers avoid dynamic memory allocation because it's so painful is probably the best feature of the language.
- fanf2 6y agoExternal arrays are static, they do not involve any dynamic allocation.
- TonyTrapp 6y agoIt's not clear from the question whether GP just wonders about the strange syntax used to reserve the space or about allocating a fixed amount of memory. The "however-many-bytes-are-needed" part sounded to me like they thought that a dynamic amount of memory should be allocated.