[comp.lang.c] Micro Soft C v.4.0 allocation problem

hman@mit-amt.UUCP (05/06/87)

I have been having a problem with MSC v.4.0 that I hope someone can
help me with.  I will also contact Micro Soft, but I'm on a deadline,
and  I'm affraid that they will take too long.

According to the Run Time Library Reference Manual, calloc should
return NULL if there is insufficient memory available.

I do a lot of callocing in my program.  It works fine up to a point,
then calloc returns a pointer which points to the middle of a position
I had previously callocated.  

The program is quite large and I've run out of data space (huge model, 640K)
before.  I don't think this is the problem though, since I have spend
the last few months optimizing memory and cutting out unnecessary
functions.  

Do any of you know why calloc is doing this and if there are any ways
around it?  Is this an honest to goodness bug?

Any help appreciated.

Send Mail to 	hman@media-lab.MEDIA.MIT.EDU

or 		Harry Morris 150 Spring St. Camb. MA 02141

edw@ius2.cs.cmu.edu (Eddie Wyatt) (05/06/87)

  Just write a simple test program  like the following:

	extern char *calloc();

	main()
	    {
	    while (calloc((unsigned) 10) != NULL);
 	    printf("Returned NULL\n");
	    }

  You may want to check the addresses returned by calloc to may sure
that they are all ascending or dsecending order.  If they are not then
this might, but not necessarily, indicate something is wrong with
calloc.

  Since you are using calloc in a large system, there are many ways 
in which memory heap can get corrupted.  Things I have run up against
are:

	1. accessing memory that was freed

	2. over indexing arrays

	3. not allocating enough memory for what I am storing

  SUN systems provide a debugging package for the memory allocation routines
malloc_debug(level) and malloc_verify() in /usr/lib/debug/malloc.o.  I don't
know if your system does but I have these VERY useful.

-- 
					Eddie Wyatt

e-mail: edw@ius2.cs.cmu.edu