|
|
Subscribe / Log in / New account

GCC begins move to C++

GCC begins move to C++

Posted Jun 2, 2010 18:01 UTC (Wed) by Cyberax (✭ supporter ✭, #52523)
In reply to: GCC begins move to C++ by dgm
Parent article: GCC begins move to C++

This code will most probably SEGFAULT in C if allocation fails and malloc() returns NULL.

Is it better than a thrown exception?


to post comments

You are right of course...

Posted Jun 3, 2010 21:07 UTC (Thu) by khim (subscriber, #9252) [Link]

This is exactly why you CAN'T write such code in gcc. malloc is forbidden there at include file level. Instead you'll use xmalloc - it can not ever return NULL, so there are no need to check the error code.

malloc() failure

Posted Jun 4, 2010 9:46 UTC (Fri) by jrn (subscriber, #64214) [Link] (1 responses)

On Linux, this is true but mostly irrelevant. Most systems overcommit (it is hard to find a saner thing to do if the user wants large programs to be able to fork() but does not provide the swap to back them) and malloc almost never fails.

malloc() failure

Posted Jun 7, 2010 9:47 UTC (Mon) by nye (subscriber, #51576) [Link]

There are other reasons malloc can fail beyond having no free memory. In zfs-fuse they recently had to add code to increase max_map_count dynamically because ZFS makes so many allocations that it could easily blow right past the default limit, causing memory allocation failures.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds