4 ms·
> No dynamic allocation unless it can't be avoided (and performance/optimization is not a valid excuse). Eliminating dynamic allocation is a performance optimi
by DaiPlusPlus 3y ago
> No dynamic allocation unless it can't be avoided (and performance/optimization is not a valid excuse).
Eliminating dynamic allocation is a performance optimisation, I’d have thought?
- dwattttt 3y agoNot if it precludes using a more efficient algorithm/mechanism vs the hoops you'd have to jump through to get something functional without it
- trealira 3y agoSometimes, if your computer has memory to spare, allocating more memory will make the program faster. For example, I've read a paper that found that, for a compiler written in C, allocating tree nodes using arenas and deallocating arenas all at once sped up the program at the cost of more memory usage (compared to maintaining a free list). Allocation was quicker because it was usually just a pointer bump, not navigating a linked list, and deallocation was quicker because the arena chunk was marked as free, not individual nodes. I imagine it would be similar with eliminating dynamic allocation vs having it. For example, I assume it would be more performant for an implementation of printf to dynamically allocate space for its result and write a whole line to stdout at once than to, for instance, make a system call to write each byte to stdout while avoiding dynamic allocation. I can't think of any better examples for a bare metal context at the moment, though.
- shiroiuma 3y agoNo. Eliminating dynamic allocation is to make the program deterministic. The whole point of standards like MISRA or DO-134(b) (for aviation) are to make software deterministic and predictable, not to make them fast. On embedded systems like this, they usually do things like disabling on-chip caches because those are non-deterministic; this of course kills performance, but it doesn't matter.