|
|
Up |
|
|
  |
Author: hotadvicehotadvice Date: Sep 21, 2007 22:16
hi there
i think this is an off topic question
but i think u folks ,,,here know the best....
so ....
case 1)
say i have 5 global variables.
int g_var1,g_var2,g_var3,g_var4,g_var5;
this will increase the data segment size needed by my program by 20
bytes (assuming sizeof(int) is 4 bytes).
case 2)
now if i do this
struct global_info {
int g_var1;
int g_var2;
int g_var3;
int g_var4;
int g_var5;
};
|
| Show full article (1.07Kb) |
|
| | 14 Comments |
|
  |
Author: Ian CollinsIan Collins Date: Sep 21, 2007 22:59
hotadvice wrote:
>
> offcourse i am in a very resource constrained environemnt and we are
> always
> told to reduce data size as much as possible..
>
You can't get something for nothing, if you require a modifiable
instance of an object, you will require an object's worth of data memory.
--
Ian Collins.
|
| |
|
| | no comments |
|
  |
Author: Army1987Army1987 Date: Sep 22, 2007 03:07
On Sat, 22 Sep 2007 05:16:18 +0000, hotadvice wrote:
[snip]
> case 1)
> say i have 5 global variables.
>
> int g_var1,g_var2,g_var3,g_var4,g_var5;
>
> this will increase the data segment size needed by my program by 20
> bytes (assuming sizeof(int) is...
|
| Show full article (1.47Kb) |
| no comments |
|
  |
Author: Malcolm McLeanMalcolm McLean Date: Sep 22, 2007 03:22
> say i have 5 global variables.
>
> int g_var1,g_var2,g_var3,g_var4,g_var5;
>
> this will increase the data segment size needed by my program by 20
> bytes (assuming sizeof(int) is 4 bytes).
>
>
> case 2)
>
>
> now if i do this
>
> struct global_info {
>
> int g_var1;
> int g_var2;
> int g_var3;
> int g_var4; ...
|
| Show full article (1.24Kb) |
| no comments |
|
  |
Author: hotadvicehotadvice Date: Sep 22, 2007 09:33
On Sep 22, 7:22 pm, "Malcolm McLean" btinternet.com> wrote:
> "hotadvice" gmail.com> wrote in message
>> say i have 5 global variables.
>
>> int g_var1,g_var2,g_var3,g_var4,g_var5;
>
>> this will increase the data segment size needed by my program by 20
>> bytes (assuming sizeof(int) is 4 bytes).
>
>> case 2)
>
>> now if i do this
>
>> struct global_info {
>
>> int g_var1;
>> int g_var2;
>> int g_var3;
>> int g_var4;
>> int g_var5; ...
|
| Show full article (1.88Kb) |
| no comments |
|
  |
Author: Malcolm McLeanMalcolm McLean Date: Sep 22, 2007 10:07
> by the way , it might look dirty, but what.... if i assign a global
> pointer to the
> structure variable ....declared on stack... at the top level
> function.... ( instead of passing it as an argument everywhere..
> since the top level function would be "active" for the entire duration
> the global info is used...).
>
That's acceptable.
Remember that what matters is your maximum stack / memory usage, not the
average use. There's only a benefit if you've got non-trival stack usage in
the functions not in the call tree under your global structure.
|
| |
| no comments |
|
  |
Author: hotadvicehotadvice Date: Sep 22, 2007 11:13
thanks
by the way ..
Defining a structure type will at least lead to increase in code text
size.
|
| |
| no comments |
|
  |
Author: Malcolm McLeanMalcolm McLean Date: Sep 22, 2007 11:41
> thanks
>
> by the way ..
>
> Defining a structure type will at least lead to increase in code text
> size.
>
Sure, but that's almost certainly irrelevant. I've got two 70GB hard drives
in a computer that cost about 500 pounds or 1000 dollars. So ignoring the
cost of the processor, VDU, mouse etc, you can work out how much it would
cost to store a structure definition.
|
| |
| no comments |
|
  |
Author: hotadvicehotadvice Date: Sep 22, 2007 23:18
> Sure, but that's almost certainly irrelevant. I've got two 70GB hard drives
> in a computer that cost about 500 pounds or 1000 dollars. So ignoring the
> cost of the processor, VDU, mouse etc, you can work out how much it would
> cost to store a structure definition.
hey hey , yeah.
btw in mys ystem..an embedded system...i have like not more than 5-6
kb. :(
anyway.. thanks again.
|
| |
| no comments |
|
  |
|
|
  |
Author: petepete Date: Sep 22, 2007 23:57
hotadvice wrote:
>>> Defining a structure type will at least
>>> lead to increase in code text size.
>> Sure, but that's almost certainly irrelevant.
>> I've got two 70GB hard drives
>> in a computer that cost about 500 pounds or 1000 dollars.
>> So ignoring the cost of the processor, VDU, mouse etc,
>> you can work out how much it would
>> cost to store a structure definition.
>
> hey hey , yeah.
>
> btw in mys ystem..an embedded system...i have like not more than 5-6
> kb. :(
But then you should be using a cross compiler
and the code text size should be irrelevant.
--
pete
|
| |
| no comments |
|
|
|
|