lifetime of variables inside namespaces?

hello everybody. in the code below, what would be the lifetime of integer n?

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

namespace Space{
    int n = 10;
}

int main(){
    cout << Space::n;
    return 0;
}


if i create a namespace with lots of variables, to be used as reference values to lots of different functions, will it hit the memory usage by the program? are the variables 'alive' while the program is in execution?

in my specific case, i have a class name "Style" and about 20 objects from this class, each one holding different parameters (like font color, font size, background image, etc) that will be used by hundreds of other classes. so my idea is to make a namespace and put these 20 styles inside it, to serve as reference. or is there any better way of doing it?

thanks in advance!
Your namespace is global, therefore it will exist for the life of the program.

will it hit the memory usage by the program?

Yes.

are the variables 'alive' while the program is in execution

Yes.

Namespaces are a way of qualifying names to prevent naming collisions. Namespaces have no bearing on the lifetime of a variable.

oh i see. i'll try another approach then.
thanks!
Topic archived. No new replies allowed.