812 questions
-2 votes
1 answer
199 views
Simplifying development. C++ function retaining value across calls from C++ or Python, with independent invocation in 2+ places in the same program
Having the scenario of a C++ library where a function does some calculations as it receives a container normally (not always) across multiples calls, and where the function needs to retain an ...
7 votes
1 answer
588 views
Why does "the concept of a single-threaded program doesn't exist to Rust" with respect to mutable static variables?
I'm learning Rust and while doing research on static variables I came across this comment from 2018: Rust requires everything to be thread-safe (even if you're not using threads, the concept of a ...
1 vote
1 answer
72 views
Python static class variable in nested class
I have a nested class that uses static vars to have class wide parameters and accumulators. If I do it as a standalone class it works. If I do a nested class and inherit the standalone class, it works....
125 votes
12 answers
394k views
What is the use of static variable in C#? When to use it? Why can't I declare the static variable inside method?
I have searched about static variables in C#, but I am still not getting what its use is. Also, if I try to declare the variable inside the method it will not give me the permission to do this. Why? ...
232 votes
6 answers
235k views
How can I access "static" class variables within methods?
If I have the following code: class Foo(object): bar = 1 def bah(self): print(bar) f = Foo() f.bah() It complains NameError: global name 'bar' is not defined How can I ...
2 votes
1 answer
84 views
Testing functions with static variables in C
I have a problem performing several scenarios one by one in unit testing. I'm testing a function, where static variables are used and they store states of variables after previous test scenarios. Is ...
0 votes
2 answers
92 views
How to create Static jagged array in c#?
I have a list of names which is static. I want to save it in a an static jaggedArray (to avoid multiple copies of same data). I want to write something like below code public static string[][] ...
-1 votes
1 answer
1k views
In Rust, how to create a globally shared singleton with `OnceLock`?
Assuming that we need to define a singleton with global read access with thread safety, the canonical method is to use OnceLock: /// A synchronization primitive which can be written to only once. /// /...
-3 votes
1 answer
94 views
I have a question about using some shared resources as static variables [closed]
I'm a student who is studying game engine structure. I've been managing shared resources through the Singleton Patterns Manager class while creating game engines. However, as the code got longer, the ...
167 votes
2 answers
57k views
How are unnamed namespaces superior to the static keyword? [duplicate]
How are unnamed namespaces superior to the static keyword?
-1 votes
1 answer
58 views
Nested thread_local variable [duplicate]
When declaring static thread_local variable, then each thread has a copy of that variable. Imagine a thread then spins another thread, will this variable still be a copy in the nested thread?
0 votes
0 answers
102 views
How to ensure initialization of static variables without explicitly including the header file
Considering the following example: A class named ObjectFactory is defined to manage the creation of several classes. These managed classes should be registered with the factory so that we can create ...
2 votes
3 answers
137 views
Caching efficiency of using a lot of static variables and template metaprogramming C++
Suppose I have the C++ code below template <int Id> struct Foo { static inline int x {}; }; int main() { using T0 = Foo<0>; using T1 = Foo<1>; ... using T999 = ...
0 votes
1 answer
93 views
Is this static struct variable guaranteed to be zero initialized apart from the one field which isn't?
Inside a function, I have a static variable which is a struct, and only one of its fields are initialized: void func() { static constexpr xcb_change_window_attributes_value_list_t root_mask { ....
0 votes
0 answers
34 views
Wildfly - Are static variables shared between EARs?
I have an wildfly with 10 EARs inside /standalone/deployments. Each of these EARs has a lib called "my-lib.jar" on the /lib directory. This Lib has a class called ...