Proposed addition of malloc_size_np()

Vasil Dimov vd at FreeBSD.org
Tue Mar 28 06:07:16 UTC 2006


On Mon, Mar 27, 2006 at 03:20:08PM -0500, John Baldwin wrote:
> On Monday 27 March 2006 11:34, Jason Evans wrote:
[...]
> > 4) Porting code from Linux.  Case in point: Xara Xtreme, currently being 
> > ported by Vasil Dimov.  At the moment, he has to use dlmalloc.
> 
> Does it contain a G/C of its own or some such?
> 

Here is what malloc_usable_size() is used for in Xara Xtreme:
* They keep track of how much (heap) memory is available. Maybe they
  support an option like "do not use more that N MiB". This is achieved
  by a wrappers to realloc() and free() which manipulate a global?
  variable AvailableRAM - the realloc() wrapper decreases AvailableRAM
  with (newsize - oldsize) where oldsize is retrieved with
  malloc_usable_size(). The free() wrapper increases AvailableRAM with
  what is returned by malloc_usable_size().
* Debugging purposes like keeping track of how much memory they
  allocated, the filename and linenumber of the allocation
* They use a function similar to realloc(), but which receives the
  number of bytes they need to increment the buffer with, rather than
  the new size, so they call realloc(p,increment+malloc_usable_size(p))
* A lot of other miscellaneous purposes where they should really keep
  track of how many bytes they requested from malloc() rather than
  calling malloc_usable_size().

-- 
Vasil Dimov
gro.DSBeerF at dv

Testing can show the presence of bugs, but not their absence.
                -- Edsger W. Dijkstra
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 155 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20060328/953f5bfe/attachment.pgp


More information about the freebsd-arch mailing list