295 {
296
298
299 static constexpr int nThread = 10;
300 static constexpr int nCount = 50000;
301
302 {
304
305 std::vector<std::thread> threads;
306 for (int i = 0; i < nThread; i++)
307 {
308 std::thread t1([&]() {
309 std::vector<MemoryPoolTest*> objects;
310 objects.resize(nCount);
311
312 for (int j = 0; j < nCount; j++)
313 {
315
316 objects[j] = std::move(p);
317 }
318
319 for (int j = 0; j < nCount; j++)
320 {
321 MemoryPoolTest* p = objects[j];
322 delete p;
323 }
324 });
325
326 threads.push_back(std::move(t1));
327 }
328
329 for (int i = 0; i < nThread; i++)
330 {
331 threads[i].join();
332 }
333 }
334
335 {
337
338 std::vector<std::thread> threads;
339 for (int i = 0; i < nThread; i++)
340 {
341 std::thread t1([&]() {
342 std::vector<MemoryPoolTest*> objects;
343 objects.resize(nCount);
344
345 for (int j = 0; j < nCount; j++)
346 {
347 MemoryPoolTest* p = static_cast<MemoryPoolTest*>(malloc(4 * sizeof(MemoryPoolTest)));
348 new(p)MemoryPoolTest;
349
350 objects[j] = std::move(p);
351 }
352
353 for (int j = 0; j < nCount; j++)
354 {
355 MemoryPoolTest* p = objects[j];
356
357 p->~MemoryPoolTest();
358 free(p);
359 }
360 });
361
362 threads.push_back(std::move(t1));
363 }
364
365 for (int i = 0; i < nThread; i++)
366 {
367 threads[i].join();
368 }
369 }
370
371 {
373
374 std::vector<std::thread> threads;
375 for (int i = 0; i < nThread; i++)
376 {
377 std::thread t1([&]() {
378 std::vector<MemoryPoolTest*> objects;
379 objects.resize(nCount);
380
381 for (int j = 0; j < nCount; j++)
382 {
384 new(p)MemoryPoolTest;
385
386 objects[j] = std::move(p);
387 }
388
389 for (int j = 0; j < nCount; j++)
390 {
391 MemoryPoolTest* p = objects[j];
392
393 p->~MemoryPoolTest();
395 }
396 });
397
398 threads.push_back(std::move(t1));
399 }
400
401 for (int i = 0; i < nThread; i++)
402 {
403 threads[i].join();
404 }
405 }
406 }
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICESTEST_PROFILE_FUNCTION()
static void * Alloc(size_t size)
Alloc memory entry point.
static void Free(void *ptr)
Free memory entry point.