Does TC's farrealloc have a bug?

Mark Alexander alexande at borland.com
Thu Jun 20 09:05:37 AEST 1991


(Email bounced yet again, sorry.)

The far heap in BC++ has 16-byte granularity, and 4 bytes of overhead
per block.  What this means is that each block is allocated on a
16-byte boundary, and the first four bytes of each block are reserved.
If you look at the pointers returned by farmalloc() and farrealloc(),
you'll see that they're all in the form xxxx:0004.

So if your program allocates a 6-byte block, you'll actually use up 16
bytes.  A 12-byte allocation would also use 16 bytes, but a 13-byte
allocation would use 32 bytes.

One solution is allocate two of your 6-byte structures in one
call to farmalloc(), but this may make your program ugly.



More information about the Comp.lang.c mailing list