5 ms·
Yes, absolutely, allocate everything possible on the stack. But strings are the poster child for dynamic memory allocation. We only very rarely know a good upp
by marshray 13y ago
Yes, absolutely, allocate everything possible on the stack.
But strings are the poster child for dynamic memory allocation. We only very rarely know a good upper limit on the size of the actual strings at the time the code is written, yet C programmers have shipped endless numbers of bugs thinking they did.
- gsg 13y agoStack allocation needn't be unprincipled hackery. You can keep a buffer of static size on the stack (resp. in the struct) and fall back to dynamic allocation only if there is insufficient space.