www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/05/24/10:51:19

From: Kbwms AT aol DOT com
Message-ID: <6e9ba021.247ac0e2@aol.com>
Date: Mon, 24 May 1999 10:49:06 EDT
Subject: Re: Heap-Memory Function
To: eliz AT is DOT elta DOT co DOT il (Eli Zaretskii)
CC: djgpp-workers AT delorie DOT com
MIME-Version: 1.0
X-Mailer: AOL 3.0 16-bit for Windows sub 38
Reply-To: djgpp-workers AT delorie DOT com

Dear Eli Zaretskii,

On 05-23-99 at 05:34:27 EST you wrote:
>
>
> I don't know how `_msize' works, so I'm not sure what would be its
> equivalent in DJGPP.  Does it work on the `malloc' level or on the
> `sbrk' level?
>

In malloc.c, the defining memory structure (at this writing) is:

typedef struct BLOCK {
  int size;
  struct BLOCK *next;
  int bucket;
} BLOCK;


The following mini-function returns the size of the block allocated
by malloc:

/* memsize - return size of block (in bytes) allocated by malloc */
size_t
memsize(void * ptr)
{
    return  ((BLOCK *)((char *)ptr-4))->size & ~1;
}

As DJ Delorie wrote on 05-23-99 at 19:01:15 EST:
>
> Don't forget malloc() changed in 2.02!  It could change at any time.

So, it behooves a developer to be on the alert when a new version of
the library is established.

Perhaps a short function like the one above could be added to malloc.c?


K.B. Williams

- Raw text -


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