I have a class apples
class apples
{
private:
double x;
double y;
double z;
public:
//some methods
};
I want to store the pointer to apples objects in a vector. I am doing this so that i create any object in any file & use any object in any file. I used the following code to determine the max no of pointers i can store in that vector
int _tmain(int argc, _TCHAR* argv[])
{
vector<apples *> myvector;
cout<<"max :"<<myvector.max_size();
return 0;
}
it gave me:
1073741823
now, my question is that can i really store 1073741823 no of pointers in that vector or is this the memory limitation (i.e. 1073741823 bytes) of the vector?
so if there are 2 vectors
vector<int> A
&
vector<double> B
can A have 1073741823 elements & B also have 1073741823 elements? i am asking this to clarify that, the max no of elements that a vector can store does not depend on the the type of entity (int or double) being stored? (this has nothing to do with the current capacity of the vector!) Also, what would be the size of a pointer to apples object (not asking the size of apples object!)? Thank You.
This is library limitation for storing elements in a vector.
vector::max_size()
:So, you can not store more than it (and in practice maybe less than it due to system limitations)
In other words even if you have best resource (memory, CPU, ...) abilities and your elements have minimum size, you can not store more than
max_size()
And according to the comment on
max_size()
in the header file: Returns the size of the largest possible %vector.