local-variables

Is it proper to use the term "global" in a relative sense?

Please assume the following contrived JavaScript: function do_something() { var x = 5; function alert_x() { alert(x); } alert_x(); } do_something(); The variable x is local to the function do_something. It isn't a global variable because it's not available in every scope (i.e., outside of either of the functions, such...

Variable sharing inside static method

I have a question about the variables inside the static method. Does the variables inside the static method shares the same memory location or would the have separate memory? Let me make an example. public class XYZ { Public Static int A(int value) { int b = value; return b; } } If 3 different user calls exec...

How to dynamically define a class method which will refer to a local variable outside?

class C end var = "I am a local var outside" C.class_eval do def self.a_class_method puts var end # I know, this is not correct, because the 'def' created a new scope; # I am asking a solution to make it; # I also know that use 'define_method' can create a instance method without creating a new scope. # but my...

Can static local variables cut down on memory allocation time?

Suppose I have a function in a single threaded program that looks like this void f(some arguments){ char buffer[32]; some operations on buffer; } and f appears inside some loop that gets called often, so I'd like to make it as fast as possible. It looks to me like the buffer needs to get allocated every time f is called, but ...

How to use acast (reshape2) within a function in R?

I tried to use acast from reshape2 within a self written function, but had the problem that acast did not find the data I send to it. Here is my data: library("reshape2") x <- data.frame(1:3, rnorm(3), rnorm(3), rnorm(3)) colnames(x) <- c("id", "var1", "var2", "var3") y <-melt(x, id = "id", measure = c("var1", "var2", "var3")) y ...

Where are .NET local variables stored?

In IL, you can define local variables using the .locals directive. Where are these variables stored, stack or heap? ...

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 ...