Deutsch   English   Français   Italiano  
<vi7kdc$3793$7@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: The Natural Philosopher <tnp@invalid.invalid>
Newsgroups: comp.os.linux.misc
Subject: Re: Joy of this, Joy of that
Date: Wed, 27 Nov 2024 17:20:44 +0000
Organization: A little, after lunch
Lines: 45
Message-ID: <vi7kdc$3793$7@dont-email.me>
References: <vhigot$1uakf$1@dont-email.me> <mcf0P.211278$pZ%.68099@fx16.iad>
 <vhs153$1k6ft$3@dont-email.me> <wwvjzcu1chd.fsf@LkoBDZeT.terraraq.uk>
 <vhtide$1s5d5$8@dont-email.me> <wwvmshodcjt.fsf@LkoBDZeT.terraraq.uk>
 <vi01qi$2cic3$1@dont-email.me> <wwvmshnlmhm.fsf@LkoBDZeT.terraraq.uk>
 <vi2rat$318ah$4@dont-email.me> <wwviksav1i7.fsf@LkoBDZeT.terraraq.uk>
 <vi5e6t$3k9sn$1@dont-email.me> <O5u1P.72795$OVd1.12914@fx10.iad>
 <vi5tpb$3medq$3@dont-email.me> <vi71te$3vogk$11@dont-email.me>
 <vi7hl6$2snk$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Nov 2024 18:20:45 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d3a623bf95e4349e30bbb37a7e6182dd";
	logging-data="105763"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+5KoWnt2yuGEvADOnXBziIz4VOscjlAFc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:t2jeDr349VQITkk44MVN38FXj3Y=
Content-Language: en-GB
In-Reply-To: <vi7hl6$2snk$1@dont-email.me>
Bytes: 3325

On 27/11/2024 16:33, Rich wrote:
> The Natural Philosopher <tnp@invalid.invalid> wrote:
>> On 27/11/2024 01:48, Rich wrote:
>>> The only two guarantees given in that paragraph are:
>>>
>>> 1) if ptr was returned by one of the malloc's, the space referenced by
>>>      ptr is deallocated (albeit only for the first call of free(ptr), per
>>>      the second sentence);
>>> and
>>> 2) if ptr is NULL, nothing occurs.
>>
>> Exactly.  The result of anything else is implementation dependent on the
>> library.
>>
>> One might write a free that says 'look at our list of allocated blocks,
>> compare with the pointer and if no match do nothing'
>>
>> Or one that says  'look at our list of allocated block compare with the
>> pointer and if no match, segfault'
>>
>> I am not au fait with the internal of 'free()' so I cannot comment as to
>> why the first is not always the case.
> 
> I can hazzard a guess.  The time taken to perform the search, or the
> effort needed to maintain an "index structure" to perform an optimized
> search, plus the time for the optimized search, was felt to be
> excessive and wasteful when the "spec" says "don't ever do this".
> 

Look I don't know how memory allocation and de allocation is done
but my instinct would be to hold a long list of pointers to allocated 
blocks.  Possibly in order of the allocated addresses, which would make 
allocating a new block a case of finding the first gap in the list that 
is [required blocksize] and inserting a new list element, and de 
allocation a question of searching the list for a matching allocation, 
and deleting it from the list.

It would be trivial to get to the end of the list and discover that that 
was the end, and, with no match found simply ignore the free call



-- 
Climate Change: Socialism wearing a lab coat.