I started using boost::shared_ptr to handle my pointer, then after applying it to my resource manager I realized I was losing a lot of performance in initialization, and shutdown was taking 10x as long to release my memory. So, I decided to make a test program to see what was happening, and I still can't figure it out. I am assuming it has something to do with the vector, but I am not sure.
Here is the test program to test speed. On release build it allocates 79,000k in task manager in about 3 seconds, and it takes my computer about 2 minutes to free it.
I am hoping someone can help me solve this issue. If not shared_ptr just isnt going to work for me.
Code:
template<class T>
struct SPtr
{
typedef boost::shared_ptr<T> Type;
};
int main()
{
std::vector<SPtr<int>::Type> Test;
Test.resize(1000000);
std::vector<SPtr<int>::Type>::iterator it = Test.begin();
int x = 0;
for ( ; it != Test.end(); ++it )
{
(*it).reset(new int(x));
++x;
}
system("pause");
return 0;
}
Thank you for any assistance.