Why is the capacity of qvector smaller than that of std:: vector?
-
@J-Hilk std will crash also as you don't have 800MB of contiguous memory.
@Christian-Ehrlicher said in Why is the capacity of qvector smaller than that of std:: vector?:
@J-Hilk std will crash also as you don't have 800MB of contiguous memory.
I tested that, that actually works with std::vector!
But you're right, thats 800 mb!!! I did not realise !!
-
@Christian-Ehrlicher said in Why is the capacity of qvector smaller than that of std:: vector?:
@J-Hilk std will crash also as you don't have 800MB of contiguous memory.
I tested that, that actually works with std::vector!
But you're right, thats 800 mb!!! I did not realise !!
@J-Hilk said in Why is the capacity of qvector smaller than that of std:: vector?:
thats 800 mb!!! I did not realise !!
Then it will crash on first access when the memory needs to be allocated.
-
@J-Hilk said in Why is the capacity of qvector smaller than that of std:: vector?:
thats 800 mb!!! I did not realise !!
Then it will crash on first access when the memory needs to be allocated.
@Christian-Ehrlicher probably
-
@Christian-Ehrlicher probably
@J-Hilk no crash on Ubuntu 22.04.
#include <vector> #include <iostream> int main() { std::vector< double > ware1( 275111222 ); for ( auto & value : ware1 ) { value = 1.0; } std::cout << ware1[ 0 ] << " " << ware1.size() << std::endl; return 1; }
output:
1 275111222 -
@J-Hilk no crash on Ubuntu 22.04.
#include <vector> #include <iostream> int main() { std::vector< double > ware1( 275111222 ); for ( auto & value : ware1 ) { value = 1.0; } std::cout << ware1[ 0 ] << " " << ware1.size() << std::endl; return 1; }
output:
1 275111222@JoeCFD said in Why is the capacity of qvector smaller than that of std:: vector?:
o crash on Ubuntu 22.04
We already discussed the reason... You have enough contiguous memory for this test.
-
@JoeCFD said in Why is the capacity of qvector smaller than that of std:: vector?:
o crash on Ubuntu 22.04
We already discussed the reason... You have enough contiguous memory for this test.
@Christian-Ehrlicher
Ok. In that case, maybe it is better to add exception handlingint main() { try { std::vector< double > ware1( 275111222 ); for ( auto & value : ware1 ) { value = 1.0; } std::cout << ware1[ 0 ] << " " << ware1.size() << std::endl; } catch( std::bad_alloc & ex ) { std::cerr << "bad allocation caught " << ex.what(); } return 1; }
-
@Christian-Ehrlicher
Ok. In that case, maybe it is better to add exception handlingint main() { try { std::vector< double > ware1( 275111222 ); for ( auto & value : ware1 ) { value = 1.0; } std::cout << ware1[ 0 ] << " " << ware1.size() << std::endl; } catch( std::bad_alloc & ex ) { std::cerr << "bad allocation caught " << ex.what(); } return 1; }
-
-
@J-Hilk std will crash also as you don't have 800MB of contiguous memory.
@Christian-Ehrlicher said in Why is the capacity of qvector smaller than that of std:: vector?:
std will crash also as you don't have 800MB of contiguous memory.
"Contiguous" is usually not the problem. With a 64bit OS and paging you have a huge address space which can be used to create contiguous addresses. PC processors don't use 64bit pointers in hardware and IIRC it was only 52bit pointers initially. This still would give you 4 petabytes of address space per process. You only need enough free memory which can then be put anywhere inside that huge address space. You would have to produce some serious fragmentation (or other really huge data) to fill up that address space.
However, if you only have 8 GB of RAM you'll quickly might run of space if you request 800MB and a lot of other things are also running.