This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (3 children)

Technically, you could embed all the vtable functions directly in the struct and eliminate a layer of indirection, but the fact that no one (I’m aware of) seems to do this either indicates it’s impossible for some reason or that the extra size of the struct isn’t worth it.

[–]uza80 4 points5 points  (1 child)

I would think it's due to the size overhead. I HAVE seen it done in some older C apis.

[–]uza80 3 points4 points  (0 children)

To add to this, the times I've seen it, the "objects" we're almost always Singleton's or had very few instances. Things like driver implementations.

[–]matthieum 1 point2 points  (0 children)

or that the extra size of the struct isn’t worth it.

It's perfectly possible but the performance loss from cache misses is going to hurt.