new operator confuse

visual studio 2015 X64

 
auto ptr = new char[1024*1024*1024];

it takes about 344ms , ptr is not empty

 
auto ptr = new char[1024*1024*1024*100];

it takes only 1ms and ptr is not empty.
> it takes only 1ms and ptr is not empty.

ptr would be uninitialised if an exception is thrown.

1
2
3
4
5
6
7
8
9
10
11
try
{
    auto ptr = new char[nbytes] ;
    std::cout << "address: " << static_cast<const void*>(ptr) << '\n' ;
    delete[] ptr ;
}

catch( const std::exception& e )
{
    std::cerr << "*** exception: " << typeid(e).name() << " what: " << e.what() << '\n' ;
}
Topic archived. No new replies allowed.