global-variables

In C, does using static variables in a function make it faster?

My function will be called thousands of times. If i want to make it faster, will changing the local function variables to static be of any use? My logic behind this is that, because static variables are persistent between function calls, they are allocated only the first time, and thus, every subsequent call will not allocate memory for ...

python global object cache

Hello Little question concerning app architecture: I have a python script, running as a daemon. Inside i have many objects, all inheriting from one class (let's name it 'entity') I have also one main object, let it be 'topsys' Entities are identified by pair (id, type (= class, roughly)), and they are connected in many wicked ways. ...

Python threads and global vars

Say I have the following function in a module called "firstModule.py": def calculate(): # addCount value here should be used from the mainModule a=random.randint(0,5) + addCount Now I have a different module called "secondModule.py": def calculate(): # addCount value here too should be used from the mainModule a=random.rand...

Is there any way to make a variable length array global in c++?

I've created a variable length array in one function, however I need to refer to this array in a second function. The problem occurs when I put the declaration above main() seeing as its length hasn't been defined yet, my compiler gets angry. How does one typically go about this? EDIT: Here is my code so far. I need to make the ar...

Objective-C initialize (static method) called more that once?

I have code similar to this in Objective-C: SubclassOfNSObject *GlobalVariableThatShouldNeverChange; @implementation MyClass +(void) initialize { [super initialize]; GlobalVariableThatShouldNeverChange = [[SubclassOfNSObject alloc] init]; // Change more stuff with GlobalVariableThatShouldNeverChange } @end I have this r...

Making global var from inside a function in PHP

Hi, I am trying to define dynamically variables. I am using a function for this, but I don't know how to define the new var as global (because it never created before the function). is that possible ? Thanks. edit ok, this is what I've built. is it that dangerous ? function extract_values($row) { foreach ($row as $key => $val...

Access to data, BSS segments will be through using a pointer or by intructions directly addressing ?

I know when it's a matter of accessing memory of a stack frame it'll be through using stack frame pointer but I wonder about how the access to data, BSS segments containing global/static data will be, through using a pointer like stack frame pointer indicating starting point of those segments or instructions address pieces of those segme...

Objective C - Static and global variable ???

In my .m file for a class named Ad , I have 3 static strings static NSSTring *AdStateDisabled = @"disable"; static NSSTring *AdStateExpired = @"expired"; static NSSTring *AdStateActive = @"active"; I can simply use these static variables in the current class, but i cannot call them from any other class, is there a way to make these st...

in python 2.6 how do i change a global variable within a for loop

i want to change the value of a variable within a for loop, but then have the new preserved variable changed when the loop finishes my attempt (kinda simplified from what i'm actually doing) SNP is a list and compar_1 is a list of lists line_1 = empty_row for SNP1 in compar_1: global line_1 if SNP[3] == SNP1[3] compar...

iPhone -- context parameters vs. global variables

In my iPhone development, I've always used global variables for lots of stuff. The style guide in my new job says we should use context parameters instead. So I need to figure out what that means and how to do that. Can anyone explain in more detail what this means -- or point me to some code that works this way? Thanks ...

Problems trying to access to a global var

Hi, I know how to use the global variables when they are defined in a class, but I have a global variable in a main. If I want to use it inside a class, which would be the import to access it? My main is something like this Main.py: from EvolutionaryAlgorithm import EvolutionaryAlgorithm initialTimeMain = 0 if __name__ == '__main__':...

how do i print output as 5 of the following program?

# include <stdio.h> int x = 5; int main(void) { int x = 7; printf("output = %d\n", x); } The above program shows output as 7. How to print 5 in c? thanx... ...

Are global variables bad?

I have developed certain financial and accounting packages on the basis of global variable which is I want to share. Here I present the small example of global variable which is communicated between multiple forms. Form1 :- Component require :- 1. ComboBox 2. Button using System; using System.Collections.Generic; using System.Com...

Update global variable from another module in javascript?

How do I achieve it? I have a module named "tooltip" which has a "fade" function which in turn uses a global "element" variable. That variable is a reference to an element of the DOM. I want to update it from another module named "lightbox" so I could just let the "fade" function handle the fade-in effect. All my modules are declared u...

Passing a variable between frames with actionscript 3

I am new to actionscript 3.0 and I'm experiencing difficulty trying to pass a variable that is created and set in frame 1 to a dynamic text box that is added to the stage in frame 4. on frame 1 the variable is set from information entered by the user: var input_dia = ""; input_dia = pdia_input.text; and should be displayed in a dynamic...

PHP closures and implicit global variable scope

Is there a way that one can implicitly declare top-level variables as global for use in closures? For example, if working with code such as this: $a = 0; //A TOP-LEVEL VARIABLE Alpha::create('myAlpha') ->bind(DataSingleton::getInstance() ->query('c') ) ->addBeta('myBeta', function($obj){ $obj->bind(DataSing...

global variables not working..? - wordpress

Hi. I'm working on a piece of code that display a custom field from Wordpress inside a function. I need to have the variables for the custom field outside the function, then I'm using PHP's 'global' to call the variable into the function, but it isn't working. Here's the code; whats wrong with it? <?php $meta = get_post_meta($post->ID, ...