int main(){ std::cout << std::endl; { std::shared_ptr<int> sharedPtr1( new int,IntDeleter() ); std::shared_ptr<int> sharedPtr2( new int,IntDeleter() ); auto intDeleter= std::get_deleter<IntDeleter>(sharedPtr1); intDeleter->getInfo(); sharedPtr2.reset(); intDeleter->getInfo(); } createRandomNumbers(); IntDeleter().getInfo(); { // create three Smart pointer for doubles std::unique_ptr<double,DoubleDeleter > uniquePtr( new double, DoubleDeleter() ); std::unique_ptr<double,DoubleDeleter > uniquePtr1( new double, DoubleDeleter() ); std::shared_ptr<double> sharedPtr( new double, DoubleDeleter() ); std::shared_ptr<double> sharedPtr4(std::move(uniquePtr)); std::shared_ptr<double> sharedPtr5= std::move(uniquePtr1); DoubleDeleter().getInfo(); } DoubleDeleter().getInfo(); }
void SharedPointerTest1() { BR::SharedReferenceManager *pReferenceManager = new BR::SharedReferenceManager(); { SharedObjectType *sharedObj; BR::SharedPointerT<SharedObjectType> sharedPtr; BR::SharedPointerT<SharedObjectType> sharedPtr2; { sharedObj = new SharedObjectType(1); pReferenceManager->RegisterSharedObject(sharedObj); sharedPtr = BR::SharedPointerT<SharedObjectType>(sharedObj); sharedPtr2 = sharedPtr; BR::SharedPointerT<SharedObjectType> sharedPtr3 = sharedPtr; } { BR::SharedPointerT<SharedObjectType> sharedPtr4(sharedPtr); } { BR::SharedPointerT<SharedObjectType> sharedPtr5((SharedObjectType*)sharedPtr); } } pReferenceManager->UpdateReferenceManager(); std::vector<BR::Thread*> Threads; for (int iThread = 0; iThread < MAX_GROUP_ONE; iThread++) { auto thread = new ThreadGroupOne(*pReferenceManager); Threads.push_back(thread); thread->Start(); } for (int iThread = 0; iThread < MAX_GROUP_TWO; iThread++) { auto thread = new ThreadGroupTwo; Threads.push_back(thread); thread->Start(); } std::chrono::time_point<std::chrono::system_clock> start, end; start = std::chrono::system_clock::now(); while ((std::chrono::system_clock::now() - start) < std::chrono::seconds(TestScale*10)) { pReferenceManager->UpdateReferenceManager(); Sleep(100); } std::for_each(Threads.begin(), Threads.end(), [](BR::Thread* pThread) { pThread->Stop(true); delete pThread; }); Threads.empty(); for (int iEle = 0; iEle < MAX_TEST_ID; iEle++) { ThreadGroupOne::stm_PointerStorage[iEle] = BR::SharedPointerT<SharedObjectType>(); } for (int iEle = 0; iEle < MAX_TEST_ID; iEle++) { ThreadGroupTwo::stm_PointerStorage[iEle] = BR::WeakPointerT<SharedObjectType>(); } pReferenceManager->UpdateReferenceManager(); delete pReferenceManager; }