i an learning c++ and in one lesson was a code which is about exception handling. My question to this code is actually: is the output and calculation of the memory size correct? When I allocate a block of memory with new double(1000), isn't the size then 8000bytes ?
The "cerr" only counts as 1kB instead of 8kB. Am i wrong?
Thanks a lot for any answer
i got the size of 1 double with getsizeof(doulbe) to confirm it is 8Bytes.
#include <iostream>
#include <cstdlib>
#include <new>
using namespace ::std;
int main()
{
int i = 0;
double *q;
try
{
while (1)
{
q = new double[1000];
i++;
}
}
catch (bad_alloc &ex)
{
cerr << "The memory is used up. " << i
<< " Kilobyte were available." << endl;
exit(1);
}
}
Aucun commentaire:
Enregistrer un commentaire