I think we're failing to communicate due to my poor English.
Quote:
Originally Posted by
shamrock
On the contrary if performance really matters one would go with a dynamic solution in order to minimize the overhead of allocating a very large memory segment and using only a small portion of it. A static solution is not optimized in terms of memory management.
This is a question of circumstance, memory access speed is generally the same for both static and dynamic memory but if you're creating a program where (malloc()ing) and free()ing entries happens too often a static implementation (with proper algorithms to avoid overflows) should be prefered.
Quote:
Why would you need to expand a static array. Don't you think that's an oxymoron? If you need to expand an array it becomes dynamic by default. The only case where that solution won't work is the gray scenario you suggested where the number of allocated entries is more than the used ones; as in the case below where the array has 10 entries allocated and only 5 are used.
I was not referring about expanding the array itself! I was talking about expanding the number of entries inside the array (so called "
gray scenario"). The
gray situation has some indications. For instance, if the proper algorithm (avoid bound overflows) is used and we're going to add and remove many entries at a time (for example, buffer purposes).
Quote:
You won't need double level of indirection...the memory returned by malloc() will be assigned to a pointer to an object of type struct empRec that is a single level of indirection. My earlier
post showed that scenario.
Yes I never said it was imperative I just said that you where proposing a one-level solution when the user was having a two-leveled problem. I just said that pointer you refer would have to be linked inside a list (linked lists) to fulfill the user's problem or be inside a
double level pointer.
IMHO the best solution is not generally applied to every case hence there is no point saying "dynamic is the best way" or "static is the best way". The best solution is that which fits the requirements and has best performance.