J
joseph cook
Is the following code:
void foo()
{
static std::vector<int> obj (500);
obj.clear();
}
mostly equivalant in operation to the following:
void foo()
{
static bool firstTimeCalled = true;
std::vector<int> obj;
if(firstTimeCalled)
{
obj.resize(500);
firstTimeCalled = false;
}
obj.clear();
}
With regards that I am only allocating memory for the 500 ints once,
no matter how many times this function is called?
void foo()
{
static std::vector<int> obj (500);
obj.clear();
}
mostly equivalant in operation to the following:
void foo()
{
static bool firstTimeCalled = true;
std::vector<int> obj;
if(firstTimeCalled)
{
obj.resize(500);
firstTimeCalled = false;
}
obj.clear();
}
With regards that I am only allocating memory for the 500 ints once,
no matter how many times this function is called?