Quote:
When the list grows close to N elements, double the size of N and realloc the storage array (1 realloc)
I am compelled to mention: "and wait for potentially N copies".
Quote:
which *can* be a performance hit, just through function overhead
No. If you are doing literally anything beyond spinning over an empty function call, that is not going to give you a performance hit.
Quote:
literally Gigabytes free on any PC you care to run a program on
I have less than 1200 MiB free on the PC I'm using at this moment.
Stupidly using RAM is why the Java server I used to use for compatibility with old kit needed a 4 GiB swap.
The point of me throwing a couple extra GiB at a box was so that I could run more instances of software; I don't throw extra RAM at a box so moron programmers could misuse it.
Quote:
I've used it in a program that ran on an ARM chip because I *needed* to do lots of quick list-building and destruction and the individual malloc calls were killing performance.
The allocator implementation you used sucked.
Quote:
When you have 10,000 elements in an array, you can either get there by 10,000 mallocs (which might be spread throughout memory) or 1 malloc and a bit of handing off yourself.
An array can't be "spread throughout memory" from program perspective.
[Edit]
Just to be clear: I don't find a problem with the generic suggestion of "use a doubling array" when an array is actually necessary.
That said, proper use of theory, allocations, and if necessary better allocator implementations for the win.
[/Edit]
Soma