std::deque typically faster then std::list for push_back(), front(), pop_front()?

c++ moderated

Re: std::deque typically faster then std::list for push_back(), front(), pop_front()?

Postby Alberto Ganesh Barbati » Sat, 12 Jan 2008 01:07:46 GMT

Victor V. Terber ha scritto:

Of course, the only definitive answer comes from actual profiling, but 
if all modifying operation you need are push_back() and pop_front() I 
would expect deque to be more performant. Typically, the most expensive 
operation in containers is the dynamic allocation/deallocation of memory 
from the heap, while other book-keeping overhead can be almost 
negligible. A list requires a dynamic allocation/deallocation for each 
item inserted/extracted, while deque allocates memory in chunks suitable 
to accommodate several objects. The chunk size is usually small enough 
so that allocating a chunk nearly takes the same time as allocating a 
single item, therefore having a smaller number of heap operations to 
perform is definitely a plus.

HTH,

Ganesh

-- 
      [ See  http://www.**--****.com/ ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]




Return to c++ moderated

 

Who is online

Users browsing this forum: No registered users and 44 guest