std::bad_alloc
to be thrown. Obviously better practice is to send a variable, but that would cause a compile error, so I hard coded a value.std::size_t
. The program works fine IMO, using g++ in cygwin:$ time ./PrimesExe Limit is 2000000 148933 Primes Created real 0m1.210s user 0m1.123s sys 0m0.046s |
For instance: What would the OS need to do for a very large memory allocation if: a. A variable page file size, starting at a low value, growable to a fairly high value was set b. The logical volume on which the page file resides is heavily fragmented c. That logical volume does not have a lot of free space d. And a journalling file system like NTFS was being used |
std::list<std::size_t>
, but the exception happens before that, in the initialiser list. I don't see any large memory allocation yet, that happens later when the list is added to. There is only 1 object created at the beginning of the program, and the exception should be thrown straight away, so I am having trouble imagining how much of anything has been allocated at this point in the execution.std::bad_alloc
in the initialiser list.There is nothing special if the block is a try-block. |
You could put a function-try-block around the constructor. |
goto
?