0

I have a huge set of small objects that work differently, but with a common interface.
They have to stay in the same container.
I cannot use templates, because I need run-time polymorphism.

Run time efficiency is critical

Can anybody tell me which of these options is the most efficient one (in both time and space)?

- switch
- virtual functions
- function objects:


class  C {
// interface...
FO *kernel;    // function object
};
vector<C>  vc;           // this one...
vector<C*>  vpc;         // ...or this one
  • Any other option?

Thanks a lot!

Edited by happygeek: fixed formatting

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

The second option (with pointer) will be most efficient and fastest because the first option makes a copy of the object before putting it into the vector while the second one does not. And depending on the contents of class C the first option can be very very slow.

The flip side is during destruction of the vector -- you must destroy (delete) each object in the vector yourself, the vector will do that with the first option but not the second.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.