Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On Microsoft Windows after 2004.

Does the limit exist without my setting it?

array.reserve(this_number)


I have found that above a certain size, if I keep adding more items to a vector array then I get an error during execution. It compiles, but does not execute.

Thank you.

What I have tried:

Adjusting this_number and recompiling.
Posted
Updated 20-Feb-21 9:47am

That "certain size" should give you a clue to what limit you have run into. A normal 32-bit application* will have a memory access limit of 2GB while a 64-bit app will have an enormous limit. In fact, you can not put enough memory in any (consumer-level) computer available today to exceed that limit.

So, what is the maximum size limit you have found? In my apps, which are 64-bit, the only limit I have found is the amount of memory in my machine. Lately, I have been allocating 7 and 8GB and it works fine.

* normal means it does not have the LAA flag set.
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 20-Feb-21 19:10pm    
5ed.
merano99 23-Feb-21 18:42pm    
On 32 Bit Operatin Systems you get a limit at 4GB (2^32). And you probably can allocate more Memory than you have. The OS will swap memory.
Rick York,

Thank you.

I am on a 32 bit Windows operating system and my code did not work when I used larger than .reserve(68272126) . I searched for that number on Google, but did not find it.

I looked up LAA and found on Large Address Aware, LAA, 32-bit, 64-bit | Algorithms, Blockchain and Cloud[^] that the 32 bit limit is 2^32 -1 which is 4294967295 .

4,294,967,295 vs
68,272,126

That is a big difference.

I do not want to extend the LAA.

I have
Total Physical Memory	    2,048.00 MB
Available Physical Memory	1.01 GB
Total Virtual Memory	    2.00 GB
Available Virtual Memory	1.96 GB


Maybe the limit is there.

Thank you for helping me and guiding me to more information.
 
Share this answer
 
Comments
Rick York 20-Feb-21 17:31pm    
This should be posted as a comment, not a solution.

You mention a number in the range of 68M - is that the number of bytes or the number of items? If it's the latter, then multiply by the size of one item and you will have the size of the allocation.
Member 15078716 20-Feb-21 19:41pm    
I tried to move my "solution" to make it a reply to your previous post. But it does not show "Reply" for that one, just for Afzaal Ahmad Zeeshan.

My current answer is again say "Thank you Rick York."

68M is the number that I can set the .reserve(68272126) to before I put any items in the array.

Separately, if I do not size the array, but allow it to resize itself then I get the following times for putting items into a vector array:
// With a string = "1"                            
//  68,270,000 items in the array is about 3.671 seconds.                            
//  68,280,000 is about [Microsoft Visual C++ Runtime Library Error] seconds.


The VC++ error, I read somewhere, is due to a variable being not [something]. So, I have been approaching this in a variety of ways. And I certainly do not use nor intend to use Visual Studio C++. I do not even have it loaded, as a program, on my computer. I use CodeBlocks 17.12 and a GCC compiler that accompanied it.

But, in a different test I get
                            
// With a string of length 1,000,000                            
//     1,500 is about 4.703 seconds.                            
//     2,000 is about [Microsoft Visual C++ Runtime Library Runtime Error] seconds.


That, to me, looks like conflicting test results. So, I asked the question on this page "In C++11 is there a limit to a vector array size?" I do not know if that was the correct question to ask, but among the searches for logic to this, it is a question that I did not find answered.

Thank you for helping so far Rick York.
Richard MacCutchan 21-Feb-21 4:57am    
The reserve number is not the problem, it is the amount of data you are storing. A simple string of one character will take at least 8 bytes, just for the data. Add to that the control pointers and size items and you are probably using 24 or more for each string. Then you need to add control bytes for each item in the vector and you will soon hit the physical memory limit.
Rick York 20-Feb-21 21:48pm    
Do you know what this message, "Microsoft Visual C++ Runtime Library Runtime Error" means? That program is linking with the Visual C++ RTL.

As I asked before, WHAT are you putting into the vector? Writing that you can put 68M things into a vector indicates nothing without knowing what the size of them is.
Member 15078716 22-Feb-21 2:47am    
In answer to your question, "As I asked before, WHAT are you putting into the vector?" And some more in case you need that.

To create the vector array
    std::vector<std::string> v;


To set up a test of the creation time
    unsigned long   StartTime_StringCreation    = GetTickCount();

    unsigned long   StoppingTime_StringCreation;

    unsigned long   MilliSeconds_StringCreation;

    double          Seconds_StringCreation;

    std::string     Time_StringCreation;

to create the string. I varied this from 1 to 1,000,000.
// For a string of length 1,000,000 to test how long it takes to create the string

    for (int s1 = 0; s1 <= 9; s1++) // String length = 1,000,000

    {

        for (int kt = 0; kt <= 9; kt++) // String length = 100,000

        {

            for (int w1 = 0; w1 <= 9; w1++) // String length = 10,000

            {

                for (int np = 0; np <= 9; np++) // String length = 1,000

                {

                    StringBeingAdded = StringBeingAdded + "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";

                }

            }

        }

    }

To complete a test of the creation time and have the result in a variable
    StoppingTime_StringCreation = GetTickCount();

    MilliSeconds_StringCreation = StoppingTime_StringCreation - StartTime_StringCreation;

    Seconds_StringCreation      = (MilliSeconds_StringCreation) / 1000.0;

    Time_StringCreation         = std::to_string(Seconds_StringCreation);


After the string is created
To place the string into the vector. I varied this from 1 to 1,000,000.
    for ( unsigned long i = 0; i <= 100; i++ )

    {

        v.emplace_back(StringBeingAdded);

        CountOfItems = CountOfItems +1;

    }


I varied the size of the string and tested the creation times.

I varied the count of the items placed into the vector array and tested the times that it took to do that.

I am finding questions that I would like someone far more experienced than me to explain.

I have read a lot here and elsewhere and I did not find sufficient answers.

Thank you Rick York for helping me.

Please, now if I have sufficiently detailed what I am doing please advise if there is more adevice for this to be given..

Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900