mrsh icon indicating copy to clipboard operation
mrsh copied to clipboard

Switch away from mrsh_array

Open emersion opened this issue 6 years ago • 2 comments

Need a good replacement. Probably some kind of linked list.

emersion avatar Jun 06 '19 12:06 emersion

What would be the point of the replacement? I see reserving an empty space is not so memory-efficient but with a linked list there is a constant overhead of insertion (allocating memory for each new element). Additionally, random access is really expensive (even with doubly linked list), of course, if you only use it for linear access, it can be okay. Another question is cache efficiency: Even with linear access pointers to the next element could point to out-of-cache addresses.

So the question is which one would be the less annoying? Wasting some space or increasing the number of libc calls and possible cache misses?

Maybe the current solution could be a bit better with constant increments instead of 2 * array->cap. ...just an idea.

0l-l0 avatar Dec 06 '19 14:12 0l-l0

The issue is that mrsh_array is an array of pointers, not an array of values. So the "array" part is pure overhead, values are still individually allocated on the heap.

Switching to real arrays would be annoying because pointers would get invalidated when re-allocating the array.

emersion avatar Dec 06 '19 14:12 emersion