Or, if you're any good at your job and have any understanding of modern CPUs and system architectures, you're not allocating each node as an independent block but rather as a single pool which can be released with a single call to free().
Posted Jun 29, 2011 11:51 UTC (Wed) by MisterIO (guest, #36192)
[Link]
If you have a templated class which can take classes of variable dimensions( i.e. whose dimensions are dinamic at runtime), how would you do that?
You can do that for the nodes structs, but that alone would still be a minimal part of the overall allocations.
Zeuthen: Writing a C library, part 1
Posted Jun 29, 2011 17:18 UTC (Wed) by cmccabe (guest, #60281)
[Link]
Perhaps you could use a memory pool that was freed later.
Zeuthen: Writing a C library, part 1
Posted Jun 29, 2011 19:25 UTC (Wed) by MisterIO (guest, #36192)
[Link]
Yeah, I'm not saying that you can't use it in general, but that's a good optimization if you've programmed everything. If the classes that are inserted are someone else's code and they don't use the pool, then suddenly you're gonna have various different memory allocation/deallocation patterns. It could be done, is it always better? I don't know, I consider it an optimization. The suggestion would be to code it in a simple way(which doesn't mean dumb), then profile it and see if/where the bottleneck is and try to solve that and so on. Starting with a complex and optimized design that could be not needed, I'm not sure that's always a good choice.