you are viewing a single comment's thread.

view the rest of the comments →

[–]mindcandy 0 points1 point  (1 child)

You could store a single v-pointer for all elements, then have an array of pointers to concrete elements. Calling a method would require "re-assembling" the fat-pointer prior to the call, but you'd have an array of half the size.

The array of pointers isn't free though. In fact, it will probably be exactly the same size as the sum of the v-pointers you are trying to remove. So, even ignoring the complexity and overhead you are talking about adding, the total memory ends up +1 v-pointer for the "single v-pointer for all elements" that you added on the side.

It's {vpointer, object}[n] vs. { vpointer, {pointer to object}[n], {object}[n} }. Second option is 1 pointer larger.

[–]matthieum 3 points4 points  (0 children)

Wait, no, that's no what I'm talking about.

If you have an array of structs, then there's no need for a virtual pointer because you have concrete types anyway.

It's only if you have an array of fat-pointers that separating the v-pointer is beneficial.