CompuServe Messages

Realloc Problem

    10-Mar-94 16:57:12
Sb: #90411-Realloc Problem
Fm: Gus Grubba 70673,1605
To: [F] Grant Blaha [Adesk] 72540,1062
I found a bug a while ago where using either "realloc" to grow a buffer, or by simply freeing a buffer and allocating a larger one right after ( free() and malloc()) the malloc function would get mangled trying to figure the heap and crash. This was pretty consistent. My work around was to allocate the largest possible buffer, free it and then go on with business. This works ok for small buffers (up to, say, 200k). If a very large buffer is required, I would talk to PharLap directly and bypass the malloc() function all together. I also suggest if you do lots of small mallocs (very inefficient, by the way), get your own malloc function and don't trust the one in Metaware's run time library. I didn't investigate any further and I can't tell if the bug is in malloc() or in the heap allocation at init time. I also haven't done any testing with the new IPAS3 stuff. I simply kept my practice of malloc(big), free(big), malloc(needed) or talking straight to PharLap.