RE: malloc to static array

"Steve Calfee" <[email protected]> Thu, 13 Oct 2005 16:55:41 -0700
Newsgroups gmane.comp.audio.mad.devel
Message-ID <[email protected]>
>Subject: [mad-dev] malloc to static array
>Date: Thu, 13 Oct 2005 16:46:15 -0700
>
>
>Hello Everyone,
>
>Thanks for taking the time to read this. Im trying to replace some of the
>malloc's used in madlib as to avoid the overhead of malloc, since I am 
>using
>a SHARC DSP with limited memory and power.  Anyway as per Andre's February
>2002 post,he suggests using static array's to contain the data rather than 
>a
>malloc, which makes sense. My problem is that Im not sure how to do that. 
>It
>sound simple but not being an overly experienced programmer, Im not sure
>what data type the array should be to house the data within a struct. Sorry
>I've tried a number of things but just am not sure how to do this. The
>orignal code in decoder.c, mad_decoder_run function is:
>
>decoder->sync = malloc(sizeof(*decoder->sync));
>
>using an unsigned char array such as:
>
>unsigned char syncDat[2000];  //sizeof originally yields ~1650 bytes, so
>2000 should be suffice
>
>and replacing the line of code with:
>
>decoder->sync = syncDat[0];
>
>Produces the following error
>
>".\decoder.c", line 558: cc0513: {D} warning: a value of type "unsigned
>char"
>           cannot be assigned to an entity of type "struct <unnamed> *"
>     decoder->sync = syncDat[0];
>                   ^
>Its obvious Im not completely sure what Im doing here. Any advice would be
>appreciated. Thanks!
>
>Matt
>
>
>
This is really a C question. You could use either:
decoder->sync = &syncDat[0];
or
decoder->sync = syncDat;

And both of these assume that decoder->sync point to an array of unsigned 
char, ie defined
unsigned char *syncDat; or equivalent in a struct.

HTH, Steve.