473,225 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

does having more variables increases the size of program.

does having more variables increases the size of program.
Aug 17 '08 #1
9 2074
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
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.