[LC++] Fastest way to concatenate vectors

Jack Lloyd lloyd at randombit.net
Mon Jul 16 13:32:42 UTC 2007


If the lifetime of the vectors you are concatenating is longer than
the result, and they will remain constant, you could write an object
that represents the concatenation and maintains references to the
vectors. Then there is no copy or memory allocation cost (OTOH if you
ever do deallocate the underlying vector, or change it while you're
still using the concatenation, you might have a nasty bug on your
hands).

Or you might try using the new C++0x move semantics which IIRC are
implemented in GCC 4.3.

-Jack

On Fri, Jul 13, 2007 at 07:48:13PM +0200, Julien Claassen wrote:
> Hi!
>   I need to append one vector to another, but that might happen quite alot so 
> I wondered: which is the fastest way of doing it. In the end I'd create a 
> temporary vector to hold the result of the concatenation.
>  Thanks in advace!
>   Kindest regards
>          Julien
> 
> --------
> Music was my first love and it will be my last (John Miles)
> 
> ======== FIND MY WEB-PROJECT AT: ========
> http://ltsb.sourceforge.net
> the Linux TextBased Studio guide
> ======= AND MY PERSONAL PAGES AT: =======
> http://www.juliencoder.de
> 
> _______________________________________________
> This is the Linux C++ Programming List
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List



More information about the tuxCPProgramming mailing list