1 /*------------------------------------------------------------------------
2 Junction: Concurrent data structures in C++
3 Copyright (c) 2016 Jeff Preshing
5 Distributed under the Simplified BSD License.
6 Original location: https://github.com/preshing/junction
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
13 #include <junction/Core.h>
14 #include <turf/Heap.h>
15 #include <turf/Util.h>
17 #include <junction/extra/MapAdapter.h>
19 #if TURF_USE_DLMALLOC && TURF_DLMALLOC_FAST_STATS
21 using namespace turf::intTypes;
22 typedef junction::extra::MapAdapter MapAdapter;
24 static const ureg MaxPopulation = 1000000;
25 static const ureg MinPopulation = 1000;
26 static const ureg StepSize = 500;
27 static const u32 Prime = 0x4190ab09;
30 MapAdapter adapter(1);
31 MapAdapter::ThreadContext threadCtx(adapter, 0);
32 threadCtx.registerThread();
34 ureg startMem = TURF_HEAP.getInUseBytes();
36 ureg initialCapacity = MapAdapter::getInitialCapacity(MaxPopulation);
37 MapAdapter::Map* map = new MapAdapter::Map(initialCapacity);
41 while (population < MaxPopulation) {
44 for (ureg target = population + StepSize; population < target; population++) {
45 u32 key = u32(population + 1) * Prime;
47 map->insert(key, (void*) uptr(key));
50 ureg inUseBytes = TURF_HEAP.getInUseBytes();
51 mem = inUseBytes - startMem;
52 loMem = turf::util::min(loMem, mem);
53 hiMem = turf::util::max(hiMem, mem);
56 printf(" (%d, %d, %d),\n", (int) population, (int) loMem, (int) hiMem);
64 #else // TURF_USE_DLMALLOC && TURF_DLMALLOC_FAST_STATS
67 fprintf(stderr, "Must configure with TURF_USE_DLMALLOC=1 and TURF_DLMALLOC_FAST_STATS=1\n");
71 #endif // TURF_USE_DLMALLOC && TURF_DLMALLOC_FAST_STATS