@@ -297,10 +297,10 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
297
297
size_t max_allocs = 0 ;
298
298
299
299
vector2d<alloc_data> allocations;
300
- std::vector<unsigned > iters;
301
- std::vector<size_t > memused;
302
300
vector2d<next_alloc_data> next;
303
- std::vector<std::vector<next_alloc_data>::const_iterator> next_iter;
301
+ using next_alloc_data_iterator =
302
+ std::vector<next_alloc_data>::const_iterator;
303
+ std::vector<std::unique_ptr<next_alloc_data_iterator>> next_iter;
304
304
int64_t iterations;
305
305
306
306
public:
@@ -318,7 +318,6 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
318
318
allocations.resize (state.threads ());
319
319
next.resize (state.threads ());
320
320
next_iter.resize (state.threads ());
321
- memused.assign (state.threads (), 0 );
322
321
323
322
#ifndef WIN32
324
323
// Ensure that system malloc does not have memory pooled on the heap
@@ -352,8 +351,10 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
352
351
auto tid = state.thread_index ();
353
352
if (tid == 0 ) {
354
353
size_t current_memory_allocated = 0 ;
355
- for (const auto &used : memused) {
356
- current_memory_allocated += used;
354
+ for (const auto &allocationsPerThread : allocations) {
355
+ for (const auto &allocation : allocationsPerThread) {
356
+ current_memory_allocated += allocation.size ;
357
+ }
357
358
}
358
359
359
360
auto memory_used = state.counters [" provider_memory_allocated" ];
@@ -377,27 +378,24 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
377
378
next.clear ();
378
379
next_iter.clear ();
379
380
allocations.clear ();
380
- iters.clear ();
381
381
}
382
382
base::TearDown (state);
383
383
}
384
384
385
385
void bench (benchmark::State &state) {
386
386
auto tid = state.thread_index ();
387
387
auto &allocation = allocations[tid];
388
- auto &memuse = memused [tid];
388
+ auto &iter = next_iter [tid];
389
389
for (int i = 0 ; i < allocsPerIterations; i++) {
390
- auto &n = *next_iter[tid] ++;
390
+ auto &n = *(*iter) ++;
391
391
auto &alloc = allocation[n.offset ];
392
392
base::allocator.benchFree (alloc.ptr , alloc.size );
393
- memuse -= alloc.size ;
394
393
alloc.size = n.size ;
395
394
alloc.ptr = base::allocator.benchAlloc (alloc.size );
396
395
397
396
if (alloc.ptr == NULL ) {
398
397
state.SkipWithError (" allocation failed" );
399
398
}
400
- memuse += alloc.size ;
401
399
}
402
400
}
403
401
@@ -418,7 +416,6 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
418
416
auto tid = state.thread_index ();
419
417
auto &i = allocations[tid];
420
418
i.resize (max_allocs);
421
- auto &memuse = memused[tid];
422
419
auto sizeGenerator = base::alloc_sizes[tid];
423
420
424
421
for (size_t j = 0 ; j < max_allocs; j++) {
@@ -429,7 +426,6 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
429
426
return ;
430
427
}
431
428
i[j].size = size;
432
- memuse += size;
433
429
}
434
430
}
435
431
@@ -439,7 +435,6 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
439
435
for (auto &j : i) {
440
436
if (j.ptr != NULL ) {
441
437
base::allocator.benchFree (j.ptr , j.size );
442
- memused[tid] -= j.size ;
443
438
j.ptr = NULL ;
444
439
j.size = 0 ;
445
440
}
@@ -460,6 +455,6 @@ class multiple_malloc_free_benchmark : public benchmark_interface<Size, Alloc> {
460
455
j++) {
461
456
n.push_back ({dist (generator), sizeGenerator.nextSize ()});
462
457
}
463
- next_iter[tid] = n.cbegin ();
458
+ next_iter[tid] = std::make_unique<next_alloc_data_iterator>( n.cbegin () );
464
459
}
465
460
};
0 commit comments