Memory control with a vector

Reply

Join Date: Feb 2005
Posts: 78
Reputation: nanodano is an unknown quantity at this point 
Solved Threads: 2
nanodano's Avatar
nanodano nanodano is offline Offline
Junior Poster in Training

Memory control with a vector

 
0
  #1
Jun 1st, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,671
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Memory control with a vector

 
0
  #2
Jun 1st, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC