Archived

This topic is now archived and is closed to further replies.

gimp

Erasing the front of a std::vector..memcpy?

Recommended Posts

If I erased the front of a vector what the chance that it''ll just move the pointer forward and release the ram I erased rather than memcopy all the following data back to .begin() Chris Brodie http:\\fourth.flipcode.com

Share this post


Link to post
Share on other sites
IIRC it will memcpy everything to the beginning of the vector.

You might want to use a deque (double ended queue). Then it will only 'advance a pointer' if you remove stuff at the beginning (it won't free the memory though, it will keep the memory if you want to add stuff to the front of the deque later).

A deque reserves a little extra space both before and after the actual data, but it must still realloc and memcpy when it gets full, so it's very similar to a vector, only that both the front and the end work in the same way. The downside is somewhat more costly accesses than a vector (due to adding the index of the first deque element to the index you want to access).

Edited by - Dactylos on July 31, 2001 7:26:24 AM

Share this post


Link to post
Share on other sites