www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/05/08:59:12

Date: Fri, 5 Mar 1999 14:57:25 +0100
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Message-Id: <199903051357.OAA30241@acp3bf.physik.rwth-aachen.de>
To: djgpp AT delorie DOT com
Subject: Re: how to know the size of allocated memory
Newsgroups: comp.os.msdos.djgpp
Organization: RWTH Aachen, III. physikalisches Institut B
X-Newsreader: TIN [version 1.2 PL2]
Reply-To: djgpp AT delorie DOT com

In article <Pine DOT SV4 DOT 3 DOT 93 DOT 990304205056 DOT 29767A-100000 AT tagore> you wrote:
> hi,

[...]
> Is there any way by which I can find the length of
> the allocated memory block, given a pointer to the block?  

In general: no. If you really want to do that, and are willing to make
your code dependent on something as volatile as the DJGPP library
revision you're compiling with, you can look up the sources for
malloc(), and see where it stores its internal information about the
memory blocks (usually a short distance before the pointer it returns
to the application).

But again: such a feature is not available to an anywhere near
'stable' or 'portable' program, in C. If at all possible, re-think
your strategy. You'll have to either take an additional argument to
that function, or force the user to use a 'malloc()' replacement
provided by you, that keeps a record of what block was given out at
what size.

--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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