www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/10/02:37:13

Date: Sat, 10 Dec 1994 00:00:48 -0500 (EST)
From: john hoeschele <john AT umdsun2 DOT umd DOT umich DOT edu>
To: mailing list <djgpp AT sun DOT soe DOT clarkson DOT edu>
Cc: john miller <jmiller AT umdsun2 DOT umd DOT umich DOT edu>,
ece431 group -- edward mazorowicz <emazorow AT umdsun2 DOT umd DOT umich DOT edu>,
jim wailing <jwaling AT umdsun2 DOT umd DOT umich DOT edu>
Subject: Malloc

I am trying to use malloc to allocate a 2.7Mbyte chunk of memory.  The 
program compiles with no problems but when I try to execute, no memory is 
allocated and it quits.  Here is how the function is used:




typedef struct sBuf {
               UCHAR vmbuf[1728];
}tBuf

tBuf *Bptr[1600];

inside main:

if(Bptr[0] = (tBuf *)malloc(1728*sizeof(tBuf)))
   printf("There has been an error is allocating memory!!");
   exit(1);

if it continues, I load Bptr[] with 1600 pointers to various locations in 
allocated memory, but I never get there.  I always get the printf statement.

Am I using the malloc function wrong?  I tried a test program not using a 
structure but just putting in large numbers to equal out to 2.7Meg, and 
it returned an address ,so there is enough memory available.

I thought about just using a two dimensional array (array[1728][1600])
but I wanted to use the malloc function.  Can anyone give me any advice 
or input on what could a solution??? 

Would it be better to allocate each 1728 chunk of memory separate than 
the whole thing all at once??

Anything would be helpful at this point!!

Thanks -  John D Hoeschele


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019