Dynamic Memory Allocation

Stan Friesen sarima at gryphon.CTS.COM
Mon Apr 4 07:10:49 AEST 1988


In article <12694 at brl-adm.ARPA> SWANGER%AUDUCVAX.BITNET at CUNYVM.CUNY.EDU writes:
>
>I am using Microsoft C 5.0 to write a program for my AT clone (640k) and I am
>having problems with dynamic memory allocation.  My program attempts to
>dynamically allocate several arrays.  The size of these arrays varies due to
>user input.  If the user enters small values, small arrays are allocated.  If
>the user enters large values, large arrays are allocated.  I keep running out
>of memory when the user enters values that are too large....   If
>the user runs the program again and enters the next largest integer (n+1),
>the program dies for lack of memory....
>  It seems like there is
>memory out there that I am unable to allocate.  I think it has something to
>do with the Intel curse of 64k segments (but I may be wrong).  I am compiling
>my program with the large memory model, and I am using the calloc(), malloc()
>and free() functions to allocate and free this storage.  I've tried using the
>halloc() function with little success.
>
	You are probably right, it is likely that the problem is the 64K
segment limit. This "feature" has the side effect that without special
programming practices no single entity, such as an array, may be larger
than 64K! The solution depends on the C compiler. I am not very familiar
with the MS C compiler, but it may have  a 'huge' keyword for declaring
objects larger than 64K. If so the solution is to declare your pointer to
be a pointer to a 'huge' object and use halloc(). If this does not work I
you may have to write specific code to break large arrays up into sets of
smaller ones.



More information about the Comp.lang.c mailing list