C
Chris LaVelle
I don't know the easiest way to explain this so, I'm going to give an
example of how it is today....and what I'm trying to accomplish.
in the header...
typedef struct XXX_ELEMENT_tag
{
UINT8 num;
UINT8 param;
UINT16 fre1;
INT16 a1;
} ;
typedef struct XXX_ELEMENT_tag ELEMENT_T;
#define MAX_ELEMENTS 8
typedef struct XYZ_S_tag {
UINT8 num_elements;
UINT8 flag;
ELEMENT_T element[MAX_E]; /*** This is the spot ***/
} XYZ_S_tag;
And of course the S_tag structure is buried one more structure down. Say
something like:
typedef struct T_TABLE_tag
{
XYZ_S_tag run;
XYZ_S_tag walk;
.... /* alot of these */
XYZ_S_tag crawl;
} TABLE_T;
typedef struct T_TABLE_tag T_table;
And in a C file a global is initialized like this...
T_table t_table =
{
{ /* run */
2, /* Num Elements */
APPLY_WINDOW, /* Flag */
{
/* N p f a */
/* 0 */ { 2, 0, 480, -240 },
/* 1 */ { 0, 0, 0, 500 },
/* 2 */ { 0, 0, 0, 0 },
/* 3 */ { 0, 0, 0, 0 },
/* 4 */ { 0, 0, 0, 0 },
/* 5 */ { 0, 0, 0, 0 },
/* 6 */ { 0, 0, 0, 0 },
/* 7 */ { 0, 0, 0, 0 },
/* 8 */ { 0, 0, 0, 0 },
}
},
{ /* walk */
/* repeat many many times */
}
}
Ok, let's just say element is bigger than my example above and there are
about a 1000 of these, only half of which have data. I've inherited
this code and this table is occupying 300k of memory and memory's tight.
I want to delete all the filler rows and declare element in a way that
the compiler will auto size what it needs for each instance. I have the
number of elements. I would have thought something along the lines of
*element instead of element[MAX_E]. But I get warnings about the
unexpected brace for element. Is there a way to make the compiler(gcc)
auto size the space for me? In the above example I would be deleting
rows 2-8.
Any and all help is appreciated?
Thanks
cj
example of how it is today....and what I'm trying to accomplish.
in the header...
typedef struct XXX_ELEMENT_tag
{
UINT8 num;
UINT8 param;
UINT16 fre1;
INT16 a1;
} ;
typedef struct XXX_ELEMENT_tag ELEMENT_T;
#define MAX_ELEMENTS 8
typedef struct XYZ_S_tag {
UINT8 num_elements;
UINT8 flag;
ELEMENT_T element[MAX_E]; /*** This is the spot ***/
} XYZ_S_tag;
And of course the S_tag structure is buried one more structure down. Say
something like:
typedef struct T_TABLE_tag
{
XYZ_S_tag run;
XYZ_S_tag walk;
.... /* alot of these */
XYZ_S_tag crawl;
} TABLE_T;
typedef struct T_TABLE_tag T_table;
And in a C file a global is initialized like this...
T_table t_table =
{
{ /* run */
2, /* Num Elements */
APPLY_WINDOW, /* Flag */
{
/* N p f a */
/* 0 */ { 2, 0, 480, -240 },
/* 1 */ { 0, 0, 0, 500 },
/* 2 */ { 0, 0, 0, 0 },
/* 3 */ { 0, 0, 0, 0 },
/* 4 */ { 0, 0, 0, 0 },
/* 5 */ { 0, 0, 0, 0 },
/* 6 */ { 0, 0, 0, 0 },
/* 7 */ { 0, 0, 0, 0 },
/* 8 */ { 0, 0, 0, 0 },
}
},
{ /* walk */
/* repeat many many times */
}
}
Ok, let's just say element is bigger than my example above and there are
about a 1000 of these, only half of which have data. I've inherited
this code and this table is occupying 300k of memory and memory's tight.
I want to delete all the filler rows and declare element in a way that
the compiler will auto size what it needs for each instance. I have the
number of elements. I would have thought something along the lines of
*element instead of element[MAX_E]. But I get warnings about the
unexpected brace for element. Is there a way to make the compiler(gcc)
auto size the space for me? In the above example I would be deleting
rows 2-8.
Any and all help is appreciated?
Thanks
cj