SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST_F() [45/72]

SpicesTest::TEST_F ( ThreadCache_test ,
ThreadAllocateDeallocate  )

Testing Spices::ThreadCache::Allocate/Deallocate in Thread.

Definition at line 87 of file ThreadCache_test.h.

87 {
88
90
91 std::vector<std::thread> threads;
92
93 for(int i = 0; i < 5; i++)
94 {
95 std::thread t([&]() {
96 Spices::ThreadCache internalTc;
97
98 const std::unique_ptr<std::array<ThreadCacheTest*, n>> objects = std::make_unique<std::array<ThreadCacheTest*, n>>();
99 for (size_t j = 0; j < n; j++)
100 {
101 auto a = new(internalTc.Allocate(sizeof(ThreadCacheTest)))ThreadCacheTest;
102
103 EXPECT_EQ(std::get<0>(a->m_Tuple), 1);
104 EXPECT_EQ(std::get<1>(a->m_Tuple), 2.0f);
105 EXPECT_EQ(std::get<2>(a->m_Tuple), nullptr);
106
107 (*objects)[j] = std::move(a);
108 }
109
110 for (size_t j = 0; j < n; j++)
111 {
112 internalTc.Deallocate((*objects)[j], sizeof(ThreadCacheTest));
113 }
114 });
115
116 threads.push_back(std::move(t));
117 }
118
119 for (auto& t : threads)
120 {
121 t.join();
122 }
123 }
#define SPICESTEST_PROFILE_FUNCTION()
void Deallocate(void *obj, size_t size)
Recycle object memory.
void * Allocate(size_t size)
Allocate memory.
Thread memory cache. First level of memory allocator.
Definition ThrealCache.h:19