Archived

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

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

This topic is 5985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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