From: Kbwms AT aol DOT com Message-ID: <59eba0ec.2479a8c1@aol.com> Date: Sun, 23 May 1999 14:53:53 EDT Subject: Re: Heap-Memory Function To: alainm AT rcsm DOT ece DOT mcgill DOT ca (Alain Magloire), nate AT cartsys DOT com (Nate Eldredge), eliz AT is DOT elta DOT co DOT il (Eli Zaretskii) CC: djgpp-workers AT delorie DOT com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: AOL 3.0 16-bit for Windows sub 38 Reply-To: djgpp-workers AT delorie DOT com Dear Alain Magloire, Nate Eldredge and Eli Zaretskii, On 05-23-99 at 06:06:48 EST you wrote: > > > On Thu, 20 May 1999 Kbwms AT aol DOT com wrote: > > > Years ago when I worked with Microsoft C/C++, I used a function > > called _msize(). Its purpose was to return the size of a block > > of memory allocated on the heap. > [from Alain Magloire:] > Most of the time the information block is hold in an offset, -1 of the > pointer. > So p = malloc(40), you should get the size by moving back 1 and casting > to the appropriate struct. Ususally the size will be the > last field in the structure so you don't have to guess the offset. > So something like this .. might work. > [from Nate Eldredge:] > It looks like the int at offset -1 indeed. Note that the low bit > appears to be used for something else; you should mask it to 0. > > [from Eli Zaretskii:] > 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? > Thanks all. The code at free() in malloc.c tells most of the story. The low bit is hacked as Nate Eldregde points out. The minimum that one can request seems to be eight bytes (at the moment). The amount allocated seems to be a multiple of eight, too. K.B. Williams