by Greg Herlihy <greghe@[EMAIL PROTECTED]
>
May 12, 2008 at 09:39 PM
On May 12, 6:58=A0pm, Carter <carterch...@[EMAIL PROTECTED]
> wrote:
> I am currently writing some code where I have a list of objects with a
> maximum occupancy of 4. I have been employing std::vector for this but
> I was wondering how much overhead is involved. Is it better to use
> some other data structure if speed is critical i.e. maybe a struct
> like this-
>
> template <typename T>
> struct max_four
> {
> =A0 =A0 =A0 int element_count;
> =A0 =A0 =A0 T elements[4];
>
> };
>
> Or are std::vectors/lists reasonably competitive in both space/time?
A fixed-size container class such as std::tr1::array<> (or
boost::array<>) would no doubt be more efficient than using a
dynamically-sized container such as a std::vector or a std::list. I
doubt however that the overhead saved would be meaningful; you would
have to profile your program's performance to find out for certain.
Greg