Mail Archives: djgpp/1994/12/10/05:14:30
>>>>> "john" == john hoeschele <john AT umdsun2 DOT umd DOT umich DOT edu> writes:
john> typedef struct sBuf { UCHAR vmbuf[1728]; }tBuf
You're missing a semicolon at the end. Please try to post real code
if you want us to look at it; how else can we hope to spot your bug?
john> tBuf *Bptr[1600];
john> inside main:
john> if(Bptr[0] = (tBuf *)malloc(1728*sizeof(tBuf)))
john> printf("There has been an error is allocating memory!!");
john> exit(1);
Your code prints out the message and quits if malloc() returns a
nonzero pointer. But you _want_ malloc() to return a nonzero pointer,
so your test is backwards. Furthermore, without curly braces around
the two statements following the "if", your code will ALWAYS execute
the exit(1). And I assume you really meant to allocate 1600 *
sizeof(tBuf) bytes? A newline at the end of the printf string would
also be a good idea, or use puts().
john> I thought about just using a two dimensional array
john> (array[1728][1600]) but I wanted to use the malloc function.
john> Can anyone give me any advice or input on what could a
john> solution???
Using a two dimensional array will result in faster code, since the
compiler won't have to generate an extra indirection to figure out the
target address. And surely you meant "array[1600][1728]".
john> Would it be better to allocate each 1728 chunk of memory
john> separate than the whole thing all at once??
All at once, since most malloc()'s round up the size of each chunk
they allocate.
-Mat
- Raw text -