| | |
Memory control with a vector
![]() |
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
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
- Placement new (C++)
- what is object oriented???? (IT Professionals' Lounge)
- StringGrid, releasing of memory (C++)
- lists and vectors (C)
- Memory (Apple Hardware)
- How to use alloc's memory allocation functions? (C)
Other Threads in the C Forum
- Previous Thread: anyone used nextagetech ?
- Next Thread: Visual Studio 2005 & POSIX threads
| Thread Tools | Search this Thread |
adobe ansi api array asterisks binarysearch calculate centimeter char character convert copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax directory feet fflush file floatingpointvalidation fork forloop frequency givemetehcodez global grade graphics gtkgcurlcompiling hacking highest homework i/o inches infiniteloop interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. match meter microsoft mysql number odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc process program programming pyramidusingturboccodes radix read recv recvblocked repetition research scanf scheduling segmentationfault send sequential single socket socketprograming socketprogramming stack standard string suggestions systemcall threads turboc unix urboc user variable voidmain() wab win32api windows.h






