kearns@read.columbia.edu (Steve Kearns) (02/08/88)
In debugging a program of mine, I discovered that LightSpeed C has several serious problems with the memory management routines. Specifically: (*) Their malloc routine calls NewPtr, but passes an int instead of a long. Since this routine seems to work, there is probably a "feature" of the glue routines that make this a non-problem in practice. (*) The realloc routine does not try hard enough. Realloc shrinks or expands a block of memory. According to the unix definition of realloc (and the description in lSC), realloc can actually return a pointer to a new area of memory, as long as it copies the relevant contents of the old block over. This is often neccessary if the block of memory is expanding. However, the LSC realloc routine calls SetPtrSize, a toolbox routine which doesn't consider moving it if it is unable to grow. Therefore, realloc fails much more often then neccessary. (*) the free routine just calls the cfree routine, when it should actually return the value of the cfree routine. LSC is a great product; I have noticed, though, that in most compilers the libraries are an afterthought, often delegated to inexperienced programmers. Especially with memory management routines this is bad. (I found even worse problems in Aztec C's memory management, for example, several years ago) If anyone needs the code that fixes this I will be glad to supply it, although with the above description it should be easy to fix. -steve
km@cadre.dsl.PITTSBURGH.EDU (Ken Mitchum) (02/08/88)
In article <5295@columbia.edu> kearns@cs.columbia.edu writes: >LSC is a great product; I have noticed, though, that in most compilers the >libraries are an afterthought, often delegated to inexperienced programmers. >Especially with memory management routines this is bad. (I found even >worse problems in Aztec C's memory management, for example, several years ago) Yes, I experienced the same problem, not just with the memory management functions, but with other libary functions. The Lightspeed manual entry reads just like the Unix manual entry, but you look at the library sources and find entire features missing. The realloc() source simply calls SetPtrSize(), without any attempt at moving the block if unsuccessful. In all fairness, I have not yet sent Think, Inc. the $10 for the latest library sources (2.15), and I assume that they have fixed things in the latest libraries. However, the difference between the manual and th sources is still irritating. -ken mitchum univ of pgh DSL