944,008 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1074
  • C RSS
Jun 1st, 2006
0

Memory control with a vector

Expand Post »
Hi,

Let me explain a little background of the situation in case there is a wiser solution than vectors. I've got a loop running in a program, and for each loop, I need to add a new element at the end. I need to backtrack anywhere from 5 - 250 elements. The amount I need to backtrack does not remain constant throughout the program. The problem(I think) is that after a while, it would just keep allocating memory when I don't need it. At a certain point, I want to delete the first element, freeing that memory space up.

My first thought was to use a vector, but I'm not sure if there is a way to do what I want. I looked through some reference material and I found vector::resize, but it sounds like if I want to restrain it, it deletes elements at the end instead of the first elements. I'm not totally familiar with all of the STL containers, so maybe another one would suit it better. Any ideas or suggestions?
Similar Threads
Reputation Points: 36
Solved Threads: 2
Junior Poster in Training
nanodano is offline Offline
78 posts
since Feb 2005
Jun 1st, 2006
0

Re: Memory control with a vector

You might want to look into deque. It is basically a vector that has been modified to facilitate ease of deletion from front end operations. Deques are useful when you want to allow insertion or deletion at either end of the structure and you also want sequential access of elements.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: anyone used nextagetech ?
Next Thread in C Forum Timeline: Visual Studio 2005 & POSIX threads





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC