#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    2
    Rep Power
    0

    How to delete an empty vector


    Hi,
    I am trying to delete empty STL vector objects. Can any one tell me what is a convenient way to do this?
    Thanks.
  2. #2
  3. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    12
    I'm assuming you mean deleting the vector itself, rather then removing vector elements.

    When you declare a vector in your program it is declared within a scope, just like any other variable. The lifetime of the vector depends on how it is created.

    If you create a global or static vector it will persist for the lifetime of your program.

    If you create a vector using dynamic memory allocation (i.e. with new) then the pointer to it will cease to exist when it goes out of scope, and prior to that you should release the memory used for the vector with delete.

    If you create a non-dynamic vector within a function it will cease to exist when it goes out of scope, i.e. when it reaches the closing brace of the enclosing block.

    I hope that helps. If that doesn't make sense, please post some code to show how you're using the vector.

IMN logo majestic logo threadwatch logo seochat tools logo