elee24@castle.ed.ac.uk (H Bruce) (08/02/90)
I have written a C program using the large model which when compiled is about 34K in size. I want to allocate space for a huge array of just over 133K (33K long ints) but halloc() returns a NULL. I am specifiying the size of the array element to be sizeof(long) (a power of 2). What is going wrong ? The total memory requirement would appear to be 64K for the program and about 3*64K for the data but DOS say I have 530K free. Thanks, Henry Bruce.
a50@mindlink.UUCP (Cliff Lum) (08/04/90)
A NULL return indicates a memory allocation fail because of insufficient space or bad values of the arguments. here is some sample code #include <malloc.h> #define MAX_SIZE 100000L main() short huge *larray; if (( larray = (short huge *)halloc(MAX_SIZE, sizeof(short))) == NULL { printf("Alocation by halloc failed "); exit(0); } printf("Allocated"); hfree(void huge *)larray); /* free the array */ } /* also missing the { after main() */ example call p_huge = (short huge *)halloc(100000, sizeof(short));