Re: reduce c++ vector size

Discussion in 'C++' started by Ian Collins, Jun 4, 2012.

  1. Ian Collins

    Ian Collins Guest

    On 06/ 4/12 05:34 AM, sukhmeet wrote:
    > Hi,
    > I wrote a program in which I define a vector of some class objects.
    > Initially the vector has size and capacity both set to 0.
    > The moment I add an element to the vector the size is 1 and the capacity
    > jumps to 32 elements.
    > This is causing a huge overhead on my program since I need to use many such
    > vectors to load reference data with max capacity of 10 elements.
    > Is there a way to set the max vector capacity or resize it to fit the
    > vector to its size at any point of time.


    You could store pointers to the objects so the "waste" won't be so big.

    --
    Ian Collins
     
    Ian Collins, Jun 4, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    1,925
    Csaba
    Feb 18, 2006
  2. Alain Ketterlin

    Re: reduce c++ vector size

    Alain Ketterlin, Jun 3, 2012, in forum: C++
    Replies:
    0
    Views:
    330
    Alain Ketterlin
    Jun 3, 2012
  3. Rui Maciel

    Re: reduce c++ vector size

    Rui Maciel, Jun 3, 2012, in forum: C++
    Replies:
    10
    Views:
    620
    Juha Nieminen
    Jun 5, 2012
  4. Fraser Ross

    Re: reduce c++ vector size

    Fraser Ross, Jun 4, 2012, in forum: C++
    Replies:
    0
    Views:
    377
    Fraser Ross
    Jun 4, 2012
  5. Replies:
    2
    Views:
    88
    Öö Tiib
    Mar 10, 2014
Loading...

Share This Page