Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: Need a GURU...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 9 Topic 1044 of 1134
Post > Topic >>

Re: Need a GURU!!! I'm stuck.

by Carl Barron <cbarron413@[EMAIL PROTECTED] > Mar 8, 2008 at 12:20 PM

In article <clcm-20080217-0014@[EMAIL PROTECTED]
>, Chris LaVelle
<cjlavelle@[EMAIL PROTECTED]
> wrote:

> 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.

> [snip  pseudo code for var array size in struct]

> 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 auto 
> size the space for me?  In the above example I would be deleting rows
2-8.
>
   Well you can name each arrray within the array and instead of an
array of ELEMENT_T have an ELEMENT_T * in the outer struct.
Safer is to have an extern T_table[]; in the header and a separate
file with static ELEMENT_T []'s like this
/* table.h */
#include <stdint.h>

typedef struct table_data
{
   uint8_t  num;
   uint8_t  param;
   uint16_t fre1;
   int16_t a1;
} table_data;

typedef struct table_entry
{
   uint8_t  num_elements;
   uint8_t  flag;
   table_data *elements;
} table_entry;

extern table_entry table[];
/* end table.h */

/* table .c */
#include "table.h"

#define RUN_0_SIZE 2
static table_data run_0[RUN_0_SIZE] = 
   {
      }2.0,480,-240},
      {0,0,0,500}
   };
#define RUN_1_SIZE 3
static table_data run_1[RUN_1_SIZE] =
   {
      {2,3,4,6},
      {3,4,7,8},
      {5,5,6,9}
   };
/* etc */
table_entry table [] =
   {
      {RUN_0_SIZE,3,run_0},
      {RUN_1_SIZE,4,run_1},
      /* etc */
   };
 
/* end file */

This costs an additional pointer per entry in table, over min.
memory allocation for the data  but is automatic if the data
is separated this way.  You might want a short program to 
rearrange the data  in this form to be sure the size of the
array in a table entry is at least the number of entries in the
corresponding array that elements points to. 

I think this is standard c99 not sure, as I ussually code in c++.
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 9 Posts in Topic:
Need a GURU!!! I'm stuck.
Chris LaVelle <cjlavel  2008-02-17 12:04:40 
Re: Need a GURU!!! I'm stuck.
=?ISO-8859-1?Q?Hans-Bernh  2008-03-08 12:19:59 
Re: Need a GURU!!! I'm stuck.
Keith Thompson <kst-u@  2008-03-17 15:18:58 
Re: Need a GURU!!! I'm stuck.
=?UTF-8?B?SGFucy1CZXJuaGF  2008-03-20 01:09:51 
Re: Need a GURU!!! I'm stuck.
Barry Schwarz <schwarz  2008-03-08 12:20:10 
Re: Need a GURU!!! I'm stuck.
David Thompson <dave.t  2008-03-17 15:23:28 
Re: Need a GURU!!! I'm stuck.
Carl Barron <cbarron41  2008-03-08 12:20:22 
Re: Need a GURU!!! I'm stuck.
Joel Yliluoma <bisqwit  2008-03-08 12:20:33 
Re: Need a GURU!!! I'm stuck.
hnarkaytis@[EMAIL PROTECT  2008-03-08 12:21:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:43:50 CDT 2008.