Article View: comp.lang.c
Article #1997Re: is a wrapper on memory-allocation calls a good idea?
From: Lawrence D’Oliveiro
Date: Mon, 30 Nov 2026 06:00
Date: Mon, 30 Nov 2026 06:00
27 lines
2667 bytes
2667 bytes
On Sun, 29 Nov 2026 08:09:16 -0800, Andrey Tarasevich wrote: > In programs that perform non-interactive batch-style processing > (e.g. config file on input, result file on output), error handling > is usually a very simple affair: just complain and abort, no need > for any kind of post-error recovery in most cases. In such programs > wrappers around malloc/calloc/realloc work very well. The wrapper > checks for success and simply aborts the entire program with an > error message in case of failure. This allows client code to > completely forget about having to worry about this sort of errors. > I.e. it uses the wrapper under assumption that the wrapper "always > succeeds". You don’t even need a special wrapper to achieve that. On Linux systems, you can set the memory-allocation policy to “overcommit”, which basically means that, when a process asks for memory, the kernel never says no <https://manpages.debian.org/proc_sys_vm(5)>. So you don’t even need to bother to check for memory-allocation failures, because you will never get a failure status. Instead, if/when the system runs low on memory, a kernel thread known as “the dreaded OOM killer” is loosed from the mythical underground cave where it is normally kept chained, and it starts killing processes, starting with the biggest memory hogs, until sanity, in the form of an adequate memory reserve, is restored to the system. In fact, this overcommit policy is usually the default setting.
Technical Details
Message-ID:
<11ej3eh$5ajn$3@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11eh538$3fet7$1@dont-email.me> <11ehine$3kr02$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Lawrence D’Oliveiro <ldo@nz.invalid> Newsgroups: comp.lang.c Subject: Re: is a wrapper on memory-allocation calls a good idea? Date: Mon, 30 Nov 2026 06:00:49 -0000 (UTC) Organization: A noiseless patient Spider Lines: 27 Message-ID: <11ej3eh$5ajn$3@dont-email.me> References: <11eh538$3fet7$1@dont-email.me> <11ehine$3kr02$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 30 Nov 2026 06:00:51 +0000 (UTC) Injection-Info: dont-email.me; logging-data="174711"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1XNJ523HSnhjoIo0KqE/d"; posting-host="a13339aa161941cd02c77e7c540602f1" User-Agent: Pan/0.165 (Kostiantynivka) Cancel-Lock: sha1:yPynRw/Musd8OYCTJMTG4KW4QY8= sha256:+osnSwb/RLPTfPD7lK+747cxchFy+pYdvL6w6RzRL4I= sha1:4FHPIslti0+NkL6h7AJ2LFj27gg= sha256:1lJ8WNhOiB8EgGdX1/BwnKW4LPfPPqz1p5au7VqHsrA=