www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/04/02/22:11:04

Date: Sun, 2 Apr 95 19:21 MDT
From: mat AT ardi DOT com (Mat Hostetter)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Dynamic allocation question
References: <01HOV5OOOLOM8ZEIJR AT cc DOT uab DOT es> <199504022219 DOT SAA08085 AT delorie DOT com> <m0rvZ4d-000GOeC AT gwar DOT ardi DOT com>

>>>>> "Mat" == Mat Hostetter <mat AT ardi DOT com> writes:

    Mat> Some people write their own my_malloc/my_realloc/my_free that
    Mat> keep track of the block size in a portable way and use these
    Mat> routines consistently.  What you do is allocate four bytes
    Mat> more than you need with `malloc', store the size at the base
    Mat> of the allocated memory, and then return the allocated
    Mat> address plus four bytes.

I should point out that this can do Bad Things on systems where
malloc's return value needs to be aligned % 8 bytes (for doubles or 64
bit longs, etc.).

-Mat

- Raw text -


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