This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: operator new catch parameter type gcc 4.3.2


On 11/11/10 8:55 AM, "me22" <me22.ca@gmail.com> wrote:

> On Thu, Nov 11, 2010 at 03:03, Jan M <jan_m@jerseymail.co.uk> wrote:
>> 
>> I cannot make operator new fail to check this (even allocating a terabyte
>> succeeds) .
>> 
> 
> Do you have overcommit memory on?  It's possible that the kernel is
> letting it succeed.
> 
> <http://opsmonkey.blogspot.com/2007/01/linux-memory-overcommit.html>

I'm more of a sysadmin than a software engineer (hey, nobody's perfect) but
have lost count of the number of times a software engineer would get tunnel
vision and not check the amount of system memory or free memory before
allocating, then try to use and crash.

Most of the newer Linux kernels have overcommit turned on because of the
ability to swap and all that, will cheerfully allow you to new[] as much
memory as you want and I've even seen instance wheres malloc and memset have
succeeded even when there's not enough physical memory to go around.

It's pretty easy to check the total memory, free memory and swap before
new'ing anything :-)

-b


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]