[comp.lang.c] Dynamic Memory Allocation

SWANGER%AUDUCVAX.BITNET@CUNYVM.CUNY.EDU (03/29/88)

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.  There is a point
where if a user enters an integer (say n), the program works correctly.  If
the user runs the program again and enters the next largest integer (n+1),
the program dies for lack of memory.  At first I thought I had reached the
limit of my 640k, but when I ran my program on a 256k machine I was able to
allocate exactly as much memory as I could with 640k.  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.  I've read the MSC manuals on this
subject, but I obviously don't understand everything.

I need help.  I would appreciate all suggestions, tips and memory allocation
routines that any of you think may be helpful.


--------------------------------------------------------------------------------

David Swanger
Academic Computing Services
200 L Building
Auburn University, AL  36849
Telephone: 205-826-4813              |-----------------------------------------|
                                     |                                         |
SWANGER@AUDUCVAX  (BITNET address)   |      My opinions are my own ... etc.    |
                                     |                                         |
--------------------------------------------------------------------------------

sarima@gryphon.CTS.COM (Stan Friesen) (04/04/88)

In article <12694@brl-adm.ARPA> SWANGER%AUDUCVAX.BITNET@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.