We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More


Dear Students! Share your Assignments / GDBs files as you receive in your LMS, So it can be discussed/solved timely. Files Upload Here.

Graded Discussion Board (GDB) of CS201 will open on Thursday August 07, 2014 and close on Friday August 08, 2014. GDB will remain open for two days, you are required to post your comments within due date.

GDB topic: 

Is it more expensive to use too many static variables instead of ordinary variables?  If yes, then how?

Your answer must be concise and not be more than 200 words.


Note: Keep you comment brief and to the point, GDB will not be accepted through email in any case.

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 3303

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Replies to This Discussion

Please Discuss here about this GDB.Thanks

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

Dear Students Don’t wait for solution post your problems here and discuss ... after discussion a perfect solution will come in a result. So, Start it now, replies here give your comments according to your knowledge and understandings....

It's not a problem. However, it is generally accepted good design practice to limit the scope of every variable so that it's as wide as it needs to be - but no wider ;-) 

This means that: 
- you don't use a method local variable as the controlled variable of a for loop, if you can declare the controlled variable in the for loop heading. 
- you don't use a class global variable (field) inside a method if you can instead use a local variable declared inside the method. 
- you don't declare a field public if it can be protected, nor protected if it can be private. 
- you don't declare a field static if it can be non-static. 
- class level "final" values should be declared static. 

There's no difference in performance between accessing static and non-static variables.

Moreover statics reduce the inter-dependencies on the other parts of the code. They can act as perfect state holders. Adding to this I find that statics are widely implemented in some languages like Smalltalk and scale So why is this oppression for statics prevalent among programmers (especially in the world of Java)?

Static variables represent global state. That's hard to reason about and hard to test: if I create a new instance of an object, I can reason about its new state within tests. If I use code which is using static variables, it could be in any state - and anything could be modifying it.

I could go on for quite a while, but the bigger concept to think about is that the tighter the scope of something, the easier it is to reason about. We're good at thinking about small things, but it's hard to reason about the state of a million line system if there's no modularity. This applies to all sorts of things, by the way - not just static variables.

That lately seems to be an argument, whether code testable or not. It's a rather flawed reasoning. The argument should be 'good design', and usually good design is testable. But not the other way around: "I can't test it therefor it must be bad design

In a statically typed language, every variable name is bound both

  • to a type (at compile time, by means of a data declaration)
  • to an object.

The binding to an object is optional — if a name is not bound to an object, the name is said to be null.

Once a variable name has been bound to a type (that is, declared) it can be bound (via an assignment statement) only to objects of that type; it cannot ever be bound to an object of a different type. An attempt to bind the name to an object of the wrong type will raise a type exception.

in a dynamically typed language, every variable name is (unless it is null) bound only to an object.

Names are bound to objects at execution time by means of assignment statements, and it is possible to bind a name to objects of different types during the execution of the program.

There is widespread confusion or disagreement about the meanings of the wordsstatic, dynamic, strong and weak when used to describe the type systems of programming languages.

Here is a description of the way (or at least one of the ways) these terms are most commonly used.

I'd believe that it would be more expensive to use static variables instead ordinary variables due to the fact that automatic variables are created and destroyed when they go in and out of scope (so memory is freed after the program is out of the block in which a variable is declared). Whereas static variables are stored until the program terminates - meaning they remain allocated even if you don't need them in your program after a certain point; which is "wasted" memory.

Would you agree with me?

yes you are right

In my humble opinion, one of the biggest mistakes the designers of the ‘C’ language made, was to make the scope of all functions global by default. In other words, whenever you write a function in ‘C’, by default any other function in the entire application may call it. To prevent this from happening, you can declare a function as static, thus limiting its scope to typically the module it resides in. Thus a typical declaration looks like this:

static void function_foo(int a)

{

}

Now I’d like to think that the benefits of doing this to code stability are so obvious that everyone would do it as a matter of course. Alas, my experience is that those of us that do this are in a minority. Thus in an effort to persuade more of you to do this, I’d like to give you another reason – it can lead to much more efficient code. To illustrate how this comes about, let’s consider a module called adc.c This module contains a number of public functions (i.e. functions designed to be called by the outside world), together with a number of functions that are intended to be called only by functions within adc.c. Our module might look something like this:

void adc_Process(void)

{

 ...

 fna();

 ...

 fnb(3);

}

...

void fna(void)

{

  ...

}

 

void fnb(uint8_t foo)

{

 ...

}

At compile time, the compiler will treat fna() and fnb() like any other function. Furthermore, the linker may link them ‘miles’ away from adc_Process(). However, if you declare fna() and fnb() as ‘static’, then something magical happens. The code would now look like this:

static void fna(void);

static void fnb(uint8_t foo);

 

void adc_Process(void)

{

 ...

 fna();

 ...

 fnb(3);

}

 

...

 

static void fna(void)

{

 ...

}

 

static void fnb(uint8_t foo)

{

 ...

}

In this case, the compiler will know all the possible callers of fna() and fnb(). With this information to hand, the compiler / linker will potentially do all of the following:

  • Inline the functions, thus avoiding the overhead of a function call.
  • Locate the static functions close to the callers such that a ‘short’ call or jump may be performed rather than a ‘long’ call or jump.
  • Look at registers used by the local functions and thus only stack the required scratch registers rather than stacking all of the registers required by the compiler’s calling convention

Together these can add up to a significant reduction in code size and a commensurate increase in execution speed.

Thus making all non public functions not only makes for better code quality, it also leads to more compact and faster code. A true win-win situation! Thus if you are not already doing this religiously, I suggest you go through your code and do it now. I guarantee you’ll be very pleased with the results

it would be more expensive to use static variables instead ordinary variables due to the fact that automatic variables are created and destroyed when they go in and out  of scope (so memory is freed after the program is out of the Block in which a variable    is declared). Whereas static variables are stored until the program terminates – meaning they remain allocated even if you don’t need them in your program after a certain point; which is “wasted” memory.

Dear Students Don’t wait for solution post your problems here and discuss ... after discussion a perfect solution will come in a result. So, Start it now, replies here give your comments according to your knowledge and understandings....

RSS

Latest Activity

Atif Malik updated their profile
15 minutes ago
Shani Gujjar updated their profile
16 minutes ago
HaMza Tufail left a comment for Aniqa Fatima
21 minutes ago
HaMza Tufail left a comment for + M.Tariq Malik
48 minutes ago
+ ! ❤INNOCENT❤ commented on + ! ❤INNOCENT❤'s photo
1 hour ago
Profile IconAmna, noor, tafseel and 15 more joined Virtual University of Pakistan
1 hour ago
Syeda left a comment for Hafiz Furqan Sabir
1 hour ago
Hadi replied to MIT's discussion Visual Programing (CS411) Assignment#01 Deadline Date = 18-11-2019 in the group CS411 Visual Programming
1 hour ago
Profile IconHadi and Fazal ur Rehman joined + M.Tariq Malik's group
1 hour ago
November 2019 replied to + M.Tariq Malik's discussion CS301 Assignment No 01 Fall 2019 Solution & Discussion in the group CS301 Data Structures
1 hour ago
KIRAN SIAF replied to + M.Tariq Malik's discussion How to Prepare The Mid Term Exams & Study in VU
1 hour ago
+ ! ! ! ! ! ! ! ! ! AG liked + M.Tariq Malik's discussion Waqar Files For Mid Term Past Papers
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked + M.Tariq Malik's discussion VU All Handouts Power Point Slides ( Handouts PPTs)
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked 彡JK彡 ❤️'s discussion Army Public School and College Mangla........ Staff required!!
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked shan's discussion project cs619
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked UMER UMER's discussion images111.jpg
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked + Iuuoɔǝut +'s discussion TERMPAPER ON ‘FINANCIAL SYSTEM OF BANGLADESH’.
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked +¢αяєℓєѕѕ gιяℓ's discussion Mera tu Mohabbat se aitbar.............:-P
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked +¢αяєℓєѕѕ gιяℓ's discussion Hazam Kary....!
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked +¢αяєℓєѕѕ gιяℓ's discussion Kashish Aur Mohabbat
2 hours ago

Today Top Members 

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service