Dear Mr. Ward:I am not much of a letter writer, but after reading the July 89 issue of The C Users Journal I felt I could save some of your readers a lot of time tracking down a problem with the Microsoft C, version 5.10 memory allocation routines. Enclosed is a listing and the output from the program.
This may help Steven Isaacson who is having memory allocation problems using Vitamin C. I found this problem after a week of tracking down a memory leak problem in a very large application. My final solution was to write my own malloc()/free() rountines that call DOS directly. This will let the DOS allocator do what is is supposed to do. No time penalty was noticed in our application.
Note if you do write your own malloc()/free() routines, call them something else! MSC uses these routines internally and makes assumptions about what data is located outside the allocated area. I always use a malloc()/free() shell to test for things like memory leaks and the free of a non-allocated block. It also will give you an easy way to install a global 'out of memory' error handler.
The code supplied by Leonard Zerman on finding the amount of free space in a system is simplistic and very limited. A better routine would build a linked list of elements and then the variable vptrarray could be made a single pointer to the head of the list. The entire routine becomes dynamic, much more robust, and there is no danger of overflowing a statically allocated array. See the supplied code for an example.
The linked list implementation has the side effect that it will work on a virtual memory system. Why you would want to do this is beyond me, but it could be considered a very time consuming way to find out what swapmax is set to on a UNIX system.
If you have any questions, please contact me. My phone number is (408) 988-3818. My fax number is (408) 748-1424.
Sincerely yours,
Jim Schimandle
Primary Syncretics
473 Sapena Court, Unit #6
Santa Clara, CA 95054Editor's Note:
If you couldn't find "Listing 1" in last month's "We Have Mail", you needn't fear the onset of any perceptual disorder there was no Listing 1. Usually publishers blame this kind of problem on someone else the printer, the typesetter, the proofreader, the paste-up artist. Unfortunately this publisher doesn't have any convenient scapegoats; I pasted up the letters section (something I often do), and failed to include the listing.
Anyway, here is the original letter and the promised listing. This time it will be right my staff is doing it.
rlw