Concern over vector length

This is a discussion on Concern over vector length within the C++ Programming forums, part of the General Programming Boards category; I intend to incorporate a feature allowing a user to recall strings input at the console using the arrow keys ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    178

    Concern over vector length

    I intend to incorporate a feature allowing a user to recall strings input at the console using the arrow keys by storing them in a vector.

    My concern is the size of the vector growing too large through extended use of the program.

    Would there be a better structure to store

    Code:
    std::string
    I like the idea of the vector because I can use an iterator

    Code:
    vector<string>::Iterator it
    to scroll through the input. I am still learning C++ and I appreciate the input received in this thread.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,622
    Of course, the second way is more clean and flexible.

    >> My concern is the size of the vector growing too large through extended use of the program.

    Average largest line: 80 characters
    Average largest amount of lines: 300

    300*80 = 24,000 characters: Almost 23.5 KBytes ( assuming the console uses 1-byte characters )

    Is that too big?
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    A vector uses dynamic memory internally, so you are not storing any of that on the stack. Based on your description of what you are doing this approach will work fine.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    178
    Thx guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vector with values outside length
    By Carola in forum C++ Programming
    Replies: 5
    Last Post: 10-09-2009, 06:43 AM
  2. just a little curious efficiency concern(!)
    By manav in forum C++ Programming
    Replies: 11
    Last Post: 05-22-2008, 10:42 AM
  3. studying c++ programing ... concern
    By azsquall in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-03-2008, 04:30 PM
  4. Win32Control design concern
    By Desolation in forum Windows Programming
    Replies: 6
    Last Post: 12-06-2007, 09:25 PM
  5. A concern..
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 04-11-2003, 12:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21