Click here to Skip to main content
15,997,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,
If we use static vector variable then it is possible to add and remove the element of that vector runtime or not?? Please give me answer..
Thank u....
Posted

1 solution

Static or not, it does not matter. It cannot change operation set, add, remove, anything.

Static objects are generally bad, or they should be used only in rare cases. They are not allocated on stack, they are not different objects per each instance of declaring type. If some type declared a static field/property, there is only one instance of in per process. No matter how many instances of the object of declaring type you have, there is only one instance of static field/property. If you have zero number of instances of the object of declaring type, a static field/property still exist. It is created per declaring type, not per instance. (Non-static members are also called instance members.)

What's bad with them? First of all, they are not inherently thread-safe. To add thread safety, synchronization should be added, say, by using a lock. Do I even have to explain why non-static members and local (stack) variables can be done thread safe without synchronization? The idea is: they can be different objects in different threads. Only when you need to share objects, you need to synchronize them.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900