static-variables

Is it OK to use static variables to cache information in ASP.net?

At the moment I am working on a project admin application in C# 3.5 on ASP.net. In order to reduce hits to the database, I'm caching a lot of information using static variables. For example, a list of users is kept in memory in a static class. The class reads in all the information from the database on startup, and will update the databa...

PHP static variables across multiple .php pages

I am building a POP3 mailbox in PHP. I have the following files: server_access.php (fetch mails from the POP3 server) data_access.php (which fetches/writes mails to local DB) mime_parser.php (parses MIME content) core.php (uses above files and stores parsed mail as an assoc array called $inbox) Now, I have the pages mailbox.php to sh...

Static variables in Python

Like in C and many other languages there are static variables which retain their value between function calls. Is there any equivalent in Python? ...

Static variables in C#.

In C#, is there a way to put a static variable in a method like VB.Net? Static myCollection As Collection ...

How to declare two different static variables? (C++)

EDIT: declaring them private was a typo, I fixed it: Relating to another question, if I declared a static variable in a class, then derived a class from that, is there any way to declare the static variable as individual per each class. Ie: class A: { public: static int x; }; class B:A { public: const static int x; }; does that defi...

C++ static initialization order

When I use static variables in C++, I often end up wanting to initialize one variable passing another to its constructor. In other words, I want to create static instances that depend on each other. Within a single .cpp or .h file this is not a problem: the instances will be created in the order they are declared. However, when you wan...

Static Variables in R

I have a function in R that I call multiple times. I want to keep track of the number of times that I've called it and use that to make decisions on what to do inside of the function. Here's what I have right now: f = function( x ) { count <<- count + 1 return( mean(x) ) } count = 1 numbers = rnorm( n = 100, mean = 0, sd = 1 ) fo...

Google App Engine: Memcache or Static variable?

Well, I think I have a very basic doubt here: I'm developing an app on GAE (Java) and performing a query to the datastore that returns a lot of entities, so I need to cache it. I was using memcache and it was working great, but if I keep the list of entities in a static variable, the whole request goes as twice as fast than using memca...

What is the difference between .LIB and .OBJ files? (Visual Studio C++)

I know .OBJ is the result of compiling a unit of compilation and .LIB is a static library that can be created from several .OBJ, but this difference seems to be only in the number of units of compilation. Is there any other difference? Is it the same or different file format? I have come to this question when wondering if the same stati...

Can I have different copies of a static variable for each different type of inheriting class

I want to have the same static variable with a different value depending on the type of class. So I would have public class Entity { public static Bitmap sprite; public void draw(Canvas canvas, int x, int y) { canvas.drawBitmap(sprite, x, y, null); } } public class Marine extends Entity { } public clas...

What's the life span of a variable in a program (in Java)?

Can you tell me how long a variable lives in a program (in Java). i.e. variables declared inside methods, variables used in parameters, STATIC variables, variables used to return from a method, etc. Thanks. ...

Remember object state in PHP between requests

I am writing an application and I will have some dictionary values in many different languages. I know I could use GetText, but AFAIR files have to be compiled after editing, and I want to let user edit dictionary, and I can't recompile .mo files on the server. I don't know how many languages will be used, so solution must be elastic. I...

Making a superclass have a static variable that's different for each subclass in c#

Without any code in the subclasses, I'd like an abstract class to have a different copy of a static variable for each subclass. In C# abstract class ClassA { static string theValue; // just to demonstrate public string GetValue() { return theValue; } ... } class ClassB : ClassA { } class ClassC : ClassA ...

static variable initialisation code never gets called

I've got an application that's using a static library I made. One .cpp file in the library has a static variable declaration, whose ctor calls a function on a singleton that does something- e.g. adds a string. Now when I use that library from the application, my singleton doesn't seem to contain any traces of the string that was suppos...

How to handle static variables in a library that is used both for desktop and web?

I have some C# library classes that make use of static variables. I use these library classes both for desktop and web applications. Problem is, as I just discovered, static variables don't go down so well on a web server; the values are shared across all sessions using the web site! How can I preserve the features of a static variabl...

Static variable

In C language, I want to access a global static variable outside the scope of the file . Let me know the best possible way to do it. One of the methods is to assign an extern global variable the value of static variable, In file a.c static int val=10; globalvar =val; In file b.c extern globalvar ; But in this case any changes in val...

Initialising a static variable in Objective-C category

I was trying to create a static variable to store a dictionary of images. Unfortunately, the best way I could find to initialise it was to check in each function that used the variable. Since I am creating this variable inside a category, I can't just initialise it inside the initialiser. Is there a neater way of initialising navigationB...

static class variable scope issue in C# winforms - why doesn't this bit of code work?

Hi, I've got two different forms in my WinForms app (MainForm and Form2 say). They both ask for an access of MyDataSet, via a "getInstance" static method. The issue is after MainForm has got an instance, when Form2 needs to get an instance the static "myDataSet" variable is null, whereas I expect to have been already set? Any ideas? ...

When should I use static methods in a class and what are the benefits?

I have concept of static variables but what are the benefits of static methods in a class. I have worked on some projects but I did not make a method static. Whenever I need to call a method of a class, I create an object of that class and call the desired method. Q: Static variable in a method holds it's value even when method is exec...

Static function-scoped pointers and memory leaks

Hi all, I've written a simple library file with a function for reading lines from a file of any size. The function is called by passing in a stack-allocated buffer and size, but if the line is too big, a special heap-allocated buffer is initialized and used to pass back a larger line. This heap-allocated buffer is function-scoped and d...