|
Title: Variables Post by: Sigma on January 27, 2011, 10:00:56 PM Hi,
can anyone explain Where static variables were stored and when they will be cleared from memory? Just static variables and not static pointers. If possible expecting the answer along with details for other variables as well. All helps are highly appreciated... Title: Re: Variables Post by: mcc on January 27, 2011, 10:27:39 PM Please be more clear in your question.
This is C++? C++ has two kinds of variables that can be called "static". One is if you define a variable typed "static". Like: static int k = 3; int something() { static int q = 2; return q++; } Each static variable you declare gets its own little slot in a fixed spot in program memory called the "BSS" segment. This memory is reserved near the beginning of the program's memory area when the program is launched and will never be cleared from memory, except when the program quits. Is this what you meant? EDIT: I remembered wrong, some static-labeled variables will be stored in the Data segment and some will be stored in the BSS segment, depending on whether you give them an initial value or not. http://en.wikipedia.org/wiki/Data_segment Title: Re: Variables- ACTIONSCRIPT 3 Post by: Sigma on January 28, 2011, 01:03:47 AM In all the languages static variables will be cleared only at the application termination point right?. If so how to clear that memory before the application terminates?(AS3)
Title: Re: Variables Post by: mcc on January 28, 2011, 01:55:37 AM I would not assume AS3 behaves the same way as C++, at all.
Title: Re: Variables Post by: Sigma on January 28, 2011, 03:20:16 AM don't just be specific. Answers from all languages are welcome.
Title: Re: Variables Post by: StudioFortress on January 28, 2011, 09:12:02 AM In Java I'd believe they would be stored within the class object of their class. For example you can load the same class multiple times and each copy of the class will have it's own static variables.
Title: Re: Variables Post by: Average Software on January 28, 2011, 09:42:08 AM Just static variables and not static pointers. I don't know if it affects your understanding or not, but you should know that pointers are variables too. Title: Re: Variables Post by: OneMoreGo on January 28, 2011, 10:37:41 AM I smell homework question. :durr:
Title: Re: Variables Post by: lapsus on January 28, 2011, 12:59:04 PM Hi, I've heard that long ropes are long, how long are they?
This thread is very confusing, we are happy to answer questions you have if you put them into a context. Randomly asking about "static" variables without knowing what it means will not give you the answers you want. So, please explain what you really want to know and why. Then, at least, I will be able to give a much better answer. Title: Re: Variables Post by: ink.inc on January 28, 2011, 02:44:17 PM I smell homework question. :durr: ___________________________________________________________________________________ To parrot what others before have been saying, this thread is impossible to answer properly without knowing the context. Title: Re: Variables- ACTIONSCRIPT 3 Post by: Trent on January 29, 2011, 04:47:23 AM If so how to clear that memory before the application terminates?(AS3) Set the variable to null? You'd also have to wait for the garbage collector to sweep through.Title: Re: Variables Post by: Sigma on February 01, 2011, 03:16:39 AM i just want to know where static variables are stored in memory(which memory) and when they will be cleared and if i want to clear that memory at runtime, how can i do that? - TAKE ANY LANGUAGE AS CONCERN.
Title: Re: Variables Post by: increpare on February 01, 2011, 03:24:47 AM Why do you want to know that?
Title: Re: Variables Post by: Sigma on February 01, 2011, 04:05:02 AM one guy asked me this question
Title: Re: Variables Post by: st33d on February 01, 2011, 04:08:44 AM Your tutor?
Static variables you would have to clear yourself. The point of having them is that you're not really keen on clearing them in the first place. Title: Re: Variables Post by: Evan Balster on February 01, 2011, 05:47:10 AM Static variables in different languages (say, Actionscript and C++) are apples and oranges. They do vaguely similar things, but in entirely different ways. Their mechanisms and semantics differ as much as anything else between the two languages.
To answer your question as a C++ programmer, you never clear static variables. It can't be done within the semantics of the language itself. Libraries might make it possible, but they would make use of things outside C++ proper. Things like operating system code and architecture-specific user-mode hacks to the effect of Cheat Engine, only far more powerful and much more dangerous if mishandled. That gray bit's just to entertain curiosity, and doesn't constitute an answer to the question. Title: Re: Variables Post by: Nix on February 01, 2011, 01:01:48 PM Clearing static variables from memory just doesn't make any sense. Calling something static is like saying "I don't want to remove this from memory."
Title: Re: Variables Post by: st33d on February 01, 2011, 01:59:09 PM I've got a setup at the moment where I need static information between a great deal of interface elements. But that static information needs to be tailored to each level. So there's a changeover point where I need to flush the data.
You could argue that I shouldn't use static variables full stop - but they make life a hell of a lot easier between change over, being pedantic about it would give me a pat on the back from computer science tutors but won't make my code readable or get my game shipped on time. However - the variables, though null, are always there. And I count on them being there. They're static. (Bear in mind that this is AS3, static variables work quite differently so I'm a bit off topic here.) Title: Re: Variables Post by: Riley Adams on February 01, 2011, 02:17:58 PM Well, you wanted a language-agnostic solution, right?... if you're alright with clearing a little more than static variables, there is one way... :durr:
(http://www.geekologie.com/images/2006/07/dell-explode.jpg) Title: Re: Variables Post by: st33d on February 01, 2011, 02:53:45 PM I'm going to have my very first mac-snob moment and say that I could probably take it to the
(I'm really not fucking kidding - anything wrong with your mac product? "Derrrrrrp! I guess we could replace it!" It's like Apple's version of turn it on and off again. Several friends have bought second hand mac products that have broken down and gotten them replaced for spanking new ones. For free.) Title: Re: Variables Post by: lapsus on February 02, 2011, 01:10:40 AM c++:
Statics are like glorified scoped globals and it makes little sense to talk about them in terms of manually "clearing" them, unless you mean deallocating memory pointed by a static pointer or such. From a simple Windows perspective; the loader maps the exe into memory - allocating space for static variables. This memory is returned when the process ends. So yeah, ask the guy that asked you the question what his use-case is and it will be easier to explain further :) Title: Re: Variables Post by: Sigma on February 02, 2011, 09:21:31 PM i cant do so its an interview question...
Title: Re: Variables Post by: Klaim on February 03, 2011, 04:18:08 AM In the end it's always language-dependent.
The idea of static variable is that it's global but access is limited to some scope (a file, a class, a function, whatever). How it is implemented is totally dependant on the language. If the job was about a specific language then you should tell us wich one for us to help you. By the way, in C++, AFAIK (but I don't have the standard doc), it is compiler-implementation dependant. That is, it static variables could be anywhere in any kind of memory, that's a decision the compiler implementer will take relative to a lot of information like the way the OS managem memory, etc. If I remember well, some implementation will put any statics directly in the stack or something. Now, in other languages that's often explicitely defined...or not, so you'll have to search. Title: Re: Variables Post by: Sigma on February 03, 2011, 08:57:52 PM Thanks for the reply guys
|