473,473 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

does having more variables increases the size of program.

does having more variables increases the size of program.
Aug 17 '08 #1
9 2082
On Sun, 17 Aug 2008 09:50:43 -0700, raashid bhatt <ra**********@gmail.com>
wrote:
does having more variables increases the size of program.
If they have linkage, yes.

Aug 17 '08 #2
On Aug 17, 9:50*am, Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz>
wrote:
On Sun, 17 Aug 2008 09:50:43 -0700, raashid bhatt <raashidbh...@gmail.com>
wrote:
does having more variables increases the size of program.

If they have linkage, yes.
sorry i didnt understand
Aug 17 '08 #3
On 17 Aug, 17:50, raashid bhatt <raashidbh...@gmail.comwrote:
does having more variables increases the size of program.
bash-3.2$ for i in a b; do echo $i.c; cat $i.c; gcc -o $i $i.c; done
a.c
int main( void ) { return 0;}
b.c
int x;
int main( void ) { return 0;}
bash-3.2$ wc -c a b
12564 a
12580 b

From which one can conclude that *on this particular
implementation* the size of the executable is in
fact larger with the additional variable. This will
probably hold for many implementations.
Aug 17 '08 #4
On 17 Aug 2008 at 16:59, raashid bhatt wrote:
On Aug 17, 9:50Â*am, Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz>
>On Sun, 17 Aug 2008 09:50:43 -0700, raashid bhatt <raashidbh...@gmail.com>
does having more variables increases the size of program.

If they have linkage, yes.

sorry i didnt understand
Static variables will be stored in your executable, either in the .bss
section (if they're uninitialized) or in the .data section (if they're
initialized), so this will add to the size of your executable.

Automatic variables are just bits of the stack at runtime, while space
that you allocated dynamically with malloc() is produced on the heap at
runtime. So these variables don't take up any storage in your
executable.

On the other hand, obviously the code to move the stack pointer to
create space for an auto variable, and any code to initialize it, will
show up in your compiled program.

Aug 17 '08 #5
Antoninus Twink wrote:
On 17 Aug 2008 at 16:59, raashid bhatt wrote:
>On Aug 17, 9:50*am, Anand Hariharan
<znvygb.nanaq.unevun...@tznvy.pbz>
>>On Sun, 17 Aug 2008 09:50:43 -0700, raashid bhatt
<raashidbh...@gmail.com>
does having more variables increases the size of program.

If they have linkage, yes.

sorry i didnt understand

Static variables will be stored in your executable, either in the .bss
section (if they're uninitialized) or in the .data section (if they're
initialized), so this will add to the size of your executable.
Typically, the .bss section occupies no space in the executable file and
the specified space is created and zeroed out at load-time.

<snip>

Aug 17 '08 #6
On 17 Aug 2008 at 18:25, santosh wrote:
Typically, the .bss section occupies no space in the executable file and
the specified space is created and zeroed out at load-time.
Of course. Nonetheless, the existence of an extra variable needs to be
recorded in the executable.

Aug 17 '08 #7
>does having more variables increases the size of program.

Probably, but it depends on what you mean by "size of program".
There are at least 3 interpretations of that:

(1) The length of the file containing the executable. (On UNIX, obtained
with ls -l, or on Windows, obtained with DIR).
(2) The value returned by the UNIX size(1) command, which includes
code, initialized data, and uninitialized data. Uninitialized data
is typically represented as a count of how large the section is,
but without needing to include a large block of zeroes in the file.
Having the OS clear the memory is usually more efficient than reading
blocks of zeroes from disk.
(3) The amount of memory taken when the program is running. This can
depend on user input, and includes automatic variables and
dynamically allocated memory (malloc() & friends).

Non-automatic initialized variables increase sizes (1), (2), and (3).
Non-automatic uninitialized variables increase sizes (2) and (3), but
typically not (1).

Automatic variables, initialized or not, require space depending
on the worst-case depth of what doesn't necessarily have to be a
stack.

Automatic initialized variables require code to initialize them,
which increases sizes (1), (2), and (3). They may also increase
size (3) for the variable itself.

Automatic uninitialized variables may increase size (3) for the
variable itself. Adding extra uninitialized variables to a function
which isn't on the worst-case path may not increase the total size
required for automatic variables unless it becomes part of the
worst-case path. Calculating the worst-case path is complicated
by recursive functions, which vary in their requirements.
Aug 17 '08 #8
santosh <sa*********@gmail.comwrote:
Antoninus Twink wrote:
On 17 Aug 2008 at 16:59, raashid bhatt wrote:
On Aug 17, 9:50*am, Anand Hariharan
<znvygb.nanaq.unevun...@tznvy.pbz>
On Sun, 17 Aug 2008 09:50:43 -0700, raashid bhatt
<raashidbh...@gmail.com>
does having more variables increases the size of program.

If they have linkage, yes.

sorry i didnt understand
Static variables will be stored in your executable, either in the .bss
section (if they're uninitialized) or in the .data section (if they're
initialized), so this will add to the size of your executable.

Typically, the .bss section occupies no space in the executable file and
the specified space is created and zeroed out at load-time.
Provided you have something called a ".bss section" at all; and anyway,
implementations are allowed to optimise in whatever way they see fit as
long as it doesn't break the semantics of correct programs, so it's
quite possible that, for example, two variables share the same space if
they're only ever used in separate parts of the program, or that, even
more likely, some variables are optimised out completely.
For example, for the two programs

#include <stdio.h>

int i;

int main(void)
{
printf("%1.1d\n", i);
return 0;
}

and

#include <stdio.h>

int main(void)
{
printf("0\n");
return 0;
}

I would not be surprised to find that the first compiles to a larger
executable with no optimisations, but exactly the same one as the second
with maximal space optimisation.

Richard
Aug 18 '08 #9
On 17 Aug, 18:41, Antoninus Twink <nos...@nospam.invalidwrote:
On 17 Aug 2008 at 16:59, raashid bhatt wrote:
On Aug 17, 9:50*am, Anand Hariharan <znvygb.nanaq.unevun...@tznvy.pbz>
On Sun, 17 Aug 2008 09:50:43 -0700, raashid bhatt <raashidbh...@gmail.com>
does having more variables increases the size of program.
If they have linkage, yes.
sorry i didnt understand

Static variables will be stored in your executable, either in the .bss
section (if they're uninitialized) or in the .data section (if they're
initialized), so this will add to the size of your executable.
this is platform specific (specificially Unix). Note the OP didn't
ask about size of executable but size of "the program". He may be
interested in runtime size. In which case automatic variables *may*
make a difference.
Automatic variables are just bits of the stack at runtime, while space
that you allocated dynamically with malloc() is produced on the heap at
runtime. So these variables don't take up any storage in your
executable.

On the other hand, obviously the code to move the stack pointer to
create space for an auto variable, and any code to initialize it, will
show up in your compiled program.

--
Nick Keighley

Aug 18 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
31
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there is not standard method to "(...) query the...
8
by: Will Chamberlain | last post by:
I came across a rather interesting article this morning and thought I'd share. We all know that Visual Studio is a great IDE, but I think we can all agree that it is adds a dramatic change to how...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
58
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
2
by: himanshubahl | last post by:
Hi, I have created a small map like this. typedef map<int,string> TEST_MAP; TEST_MAP testMap; I add about 10,000 string entries into the map like this tempStr="test Program"; for(int...
4
by: Hong Chen | last post by:
I developed a large program and found the program does not really release memory after the delete operation is taken, since, according to "performance monitor", the virtual bytes used by this...
3
by: raashid bhatt | last post by:
indeed having more variables in program increases its size, but as per i have read in many books the variables get stored in RAM not hardisk
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.