In General I would like to ask where a Member Static function's local variables are stored ?
Depends. A static constant plain old datatype may be stored in a read-only data segment. A static variable with constant initializer may be stored in the data segment, and a static variable that requires dynamic initialization may be stored in the BSS segment.
if a Static variable is used inside a static function is the variable only initialised once ?
Yes. In this case, SomeMap will be initialized the first time control passes through its declaration.
The zero-initialization (8.5) of all local objects with static storage duration (3.7.1) is performed before any
other initialization takes place. A local object of POD type (3.9) with static storage duration initialized with
constant-expressions is initialized before its block is first entered. An implementation is permitted to perform
early initialization of other local objects with static storage duration under the same conditions that an
implementation is permitted to statically initialize an object with static storage duration in namespace scope
(3.6.2). Otherwise such an object is initialized the first time control passes through its declaration; such an
object is considered initialized upon the completion of its initialization. If the initialization exits by throwing
an exception, the initialization is not complete, so it will be tried again the next time control enters the
declaration.
Section 6.7, paragraph 4 of ISO/IEC 14882:2003(E) (sorry, I don't have a more recent copy of the standard handy)
From the above code, is there an advantage of declaring SomeMap as static ?( I expect it to be only initialized once )
Yes there is an advantage to declaring it static -- it will only be initialized once and only initialized if it is used. If Test::GetSomeMap is never call, SomeMap is never initialized.
As @Blacktempel states above, however, Test::GetSomeMap should return by reference to remove any doubts about the creation of extra copies SomeMap.
You should also note that you are incurring the cost of the creation of three strings (CONST1, CONST2, and CONST3), each of which may allocate heap memory to store the a copy of their constant-expression character string initializers ("const1", "const2", "const3"). Furthermore, if you call Test::GetSomeMap, you are also incurring the cost of initializing the SomeMap vector which may also allocate heap memory to store the copies of the strings.
If you are concerned about memory usage and initialization overhead and you truly want a static constant array of strings, just declare one, like so:
static const char* const * GetSomeMap(void) {
static const char* const SomeMap[] = {"const1", "const2", "const3"};
return SomeMap;
}
SomeMap will consume a minimum of memory with no initialization overhead (and be completely unchangeable).