farrealloc() bug in Turbo C

Thomas Ray ray at vax1.acs.udel.EDU
Fri May 4 01:51:42 AEST 1990


     The function farrealloc() in Turbo C is described as ``Adjusts allocated
block in far heap....  Blocks larger than 64K can be allocated''.  The
problem is that it only works for blocks of up to 64K.  I called their
technical support, and they were not aware of the problem, but upon
examining the source code, said that in fact it would not work for blocks
larger than 64K because it first allocates another block with farmalloc(),
and then uses memmove() to move the data from the old block.  However,
memmove() only handles up to 64K and they forgot to code in the case of more
than 64K.  Stupid!

    The technician suggested that I write my own farrealloc() using
farmalloc() and memmove().  It sounded good at the time, but later I realized
that I would need to know how big the old block was in order to move it
properly (when going to a larger block).  Since that information is not
passed to the function, it must be gotten from the system and I don't know
how to do it.  There is currently a discussion on this problem in comp.lang.c
under the subject heading of malloc/free.  I called back to the technical
support to discuss the matter further, but the guy I got was very rude and
told me he didn't have time to look into it.

     So, does anyone have a piece of code that can do a farrealloc() in
Turbo C, or can anyone write and test such a function?  It would be nice
to have a farrealloc() that would try to expand the block before resorting to
the malloc()/memmove() combination.  This will be especially critical for
large blocks because there will very likely not be enough room to make another
block before discarding the old one.  If you send me a fix by email, I will
summarize and post the responses.

                             Tom Ray
                       University of Delaware
                  School of Life & Health Sciences
                      Newark, Delaware  19716
                         ray at vax1.udel.edu
                           302-451-2753



More information about the Comp.lang.c mailing list