delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/06/24/09:04:16

Message-Id: <m0yopBU-000S3tC@inti.gov.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT gov DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT gov DOT ar>
Organization: INTI
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
Date: Wed, 24 Jun 1998 10:07:35 +0000
MIME-Version: 1.0
Subject: Re: DJGPP v2.01 malloc wasting 4Kb
CC: djgpp-workers AT delorie DOT com

Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:

>> If I'm right malloc is wasting 4Kb each time we allocate a block >= 4Kb.
>> Malloc allocates one extra page and this page is simply wasted. I
>> saw it when I tried to allocate all the RAM in pages
>
>Can you post a simple test program to demonstrate this?  IIRC, this
>has come up previously, and the conclusion was that if you are careful
>in your calls to malloc (e.g., request 4KB minus 8 bytes of overhead,
>etc.), there's no waste.

If you want I can show you where is the problem in the code. The extra page
is allocated to speed-up a realloc request but if you never call realloc
you lose the memory. So a program that allocates a lot of blocks of 2041
bytes will in fact allocate 8192 bytes per block.

>> 1) Is that correct? (To test it you can make some allocations of
>> 4000 bytes and check the free memory you'll see each allocation is
>> taking 2 pages instead of 1).
>
>I think the slack space is sometimes used by malloc for smaller
>allocations (which of course doesn't help if you need all your chunks
>be 4KB).  So this isn't the complete test, you need to try smaller
>allocations after each 4KB and see if available memory changes.

Is only used when you realloc the block, it doesn't help to allocate smaller
blocks and doesn't help to realloc other blocks, only to realloc this special
block.
I think this speed up MUST be used only for blocks where an extra page isn't
so important (>=128Kb for example).

>Also, if you need whole pages of memory, why don't you use sbrk
>instead of malloc?

I don't need it at all, I just saw it in one experiment.

>> 2) Can we fix it in the distribution?
>
>Given that v2.02 tosses BSD malloc and replaces it with an entirely
>different version, why should we bother to replace malloc in v2.01?

Because nobody knows when 2.02 will be stable.

SET
------------------------------------ 0 --------------------------------
Visit my home page: http://set-soft.home.ml.org/
or
http://www.geocities.com/SiliconValley/Vista/6552/
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org
ICQ: 2951574
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019