🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2238

Re: is a wrapper on memory-allocation calls a good idea?

#2238
From: Tristan Wibberley
Date: Sat, 05 Dec 2026 08:38
44 lines
3701 bytes
On 30/11/2026 06:16, Bonita Montero wrote:
> Am 30.11.2026 um 07:00 schrieb Lawrence D’Oliveiro:
> 
>> 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.
> 
> realloc() may be necessary nevertheless when a memory chunk isn't
> large enough. With overcommit you could allocate more memory than
> needed to reduce the likehood of realloc()s.
> 

If the goal is to obtain a memory region which doesn't need to be
shuffled later then instead of allocating memory first, you can just
allocate address space. I recall you can do that on Linux with mmap to
reserve a block of addresses then another mmap to reserve actual memory.

Often mmaping an actual writable sparse file solves the problem because
it can have holes and there's no competitive unsatisfiable commitment
antagonising the other processes on a computer.

-- 
Tristan Wibberley

The message body is Copyright (C) 2026 Tristan Wibberley except
citations and quotations noted. All Rights Reserved except that you may,
of course, cite it academically giving credit to me, distribute it
verbatim as part of a usenet system or its archives, and use it to
promote my greatness and general superiority without misrepresentation
of my opinions other than my opinion of my greatness and general
superiority which you _may_ misrepresent. You definitely MAY NOT train
any production AI system with it but you may train experimental AI that
will only be used for evaluation of the AI methods it implements.
Technical Details
Message-ID: <11f0iim$2i7jn$6@dont-email.me>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11eh538$3fet7$1@dont-email.me> <11ehine$3kr02$1@dont-email.me> <11ej3eh$5ajn$3@dont-email.me> <11ej4cd$5t50$1@raubtier-asyl.eternal-september.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk>
Newsgroups: comp.lang.c
Subject: Re: is a wrapper on memory-allocation calls a good idea?
Date: Sat, 5 Dec 2026 08:38:46 +0000
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <11f0iim$2i7jn$6@dont-email.me>
References: <11eh538$3fet7$1@dont-email.me> <11ehine$3kr02$1@dont-email.me>
 <11ej3eh$5ajn$3@dont-email.me>
 <11ej4cd$5t50$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 05 Dec 2026 08:38:47 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2694775"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19gQk8df/R0n7NvXh3BMR61i65QROWVYKY8ZHkFU69fqQ=="; posting-host="e210ba6551fa09f4d8612e67f408742d"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5H/Yj1wB4YFQsX4kTKHisVFWAso= sha256:qyfX3sR3pGabofEVqcrA1eRjcM74eEI80rzDmzf8u8o=
	sha1:QvuDQMvrmyF+hWgYtjkKphRYCmg= sha256:Q5lGd0LcOXiBZpA0IRRFLN0zgCC5kSALl3ie2LS99GE=
In-Reply-To: <11ej4cd$5t50$1@raubtier-asyl.eternal-september.org>
Content-Language: en-GB