std::vector Max?

This is a discussion on std::vector Max? within the C++ Programming forums, part of the General Programming Boards category; Hey thanks for reading. I recently played around making a particle engine in which I had Particles inside a controler ...

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    404

    std::vector Max?

    Hey thanks for reading. I recently played around making a particle engine in which I had Particles inside a controler declared as a std::vector.
    ex

    Code:
    class Controler
    {
      private:
        std::vector <BaseTri> Particle;
        .....
        .....
      public:
        Controler();
        ~Controler();
        void Move();
        void PushBack();
    };
    The PushBack() function basicly caused a new particle to pop into existence every frame I figured this would keep filling in one direction with new particles until my computer exploded, but turns out it seemed to stop filling after about a minute or two, and the only way to double the number of particles was to add another std::vector and let it push back as well. So there seems to be a maximum value to a std::vector 's size, but I can't seem to find documentation on it.

    Any ideas?

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,145
    Try vector::max_size().

    But that only gives you the theoretical limit.

    The "real" limit is probably lower, due to, among other things, memory fragmentation (you can't get a piece of continuous memory big enough, even though all the free space added up would give you enough space).
    Last edited by cyberfish; 10-05-2010 at 11:10 PM.

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    404
    Ahh so it has to do with the number of bits that my class BaseTri contains? Looks like 4.28 billion bits is a little under max hard to beleive my class used all 4 billion bits before I drew even 100k triangles, probably need to optimize it a little bit. Does the bits a class requires have to do with both Functions and Variables.. or just the variables.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    The size of the class is affected primarily by the variables within it, and to some degree their ordering. It is also affected by whether or not the class contains any virtual functions, and what it inherits from.
    If you want to keep your class size small so as to fit as many of them as possible in a vector, then it would be good to post your class definition so we can help you make it smaller.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    404
    Oh I appreciate the offer, but the entire BaseTri class is under revision to incorporate Quaternion Rotation so its not really in a format that can be subject to optimization as my lack of understanding of Hamilton's laws have left it in a unworking format at the moment lol. This post was mainly just because I was interested in how versatile the std::vector has performed thus far since I started using it, and what its limitations where.

    Thanks again for the information iMalc and Cyberfish ;o).

Popular pages Recent additions subscribe to a feed

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