[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sv: Sv: Sv: Sv: Memory allocators



> #include <iostream>
>
> int main()
>    {
>
>    using namespace std;
>
>    try
>       {
>       char* x;
>       while (1)
>          {
>          x = new char [1048576];
>          if (x == 0)
>             {
>             cout << "NULL returned on memory failure" << endl;
>             break;
>             }
>          }
>       }
>    catch (...)
>       {
>       cout << "Exception caught" << endl;
>       }
>    return 0;
>    }
>
Ehh? 1.048.576 bytes is something like 1 megabyte. I do think most any
system will be able to allocate 1 megabyte of memory.

Windows can't run out of memory, though, atleast not if theres enough
harddisk space and the size of the swap-file has not been limited. It'll
happily shred your harddisk before reporting not enough memory.

And if the requested size of a block of memory is too insanely high, I
believe it refuses to allocate it by some special behavior. I know for sure
there's an ASSERT in there to check for that. It migth not behave specially
in case of release builds. I'm not sure.