Merge pull request #23 from mdw55189/issue-19
[junction.git] / samples / MallocTest / MallocTest.cpp
1 /*------------------------------------------------------------------------
2   Junction: Concurrent data structures in C++
3   Copyright (c) 2016-2017 Jeff Preshing
4
5   Distributed under the Simplified BSD License.
6   Original location: https://github.com/preshing/junction
7
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 ------------------------------------------------------------------------*/
12
13 #include <junction/Core.h>
14 #include <turf/Heap.h>
15 #include <junction/extra/MapAdapter.h>
16 #include <iostream>
17
18 using namespace turf::intTypes;
19
20 int main() {
21     junction::extra::MapAdapter adapter(1);
22     junction::extra::MapAdapter::ThreadContext context(adapter, 0);
23     junction::extra::MapAdapter::Map map(65536);
24
25     context.registerThread();
26
27     ureg population = 0;
28     for (ureg i = 0; i < 100; i++) {
29 #if TURF_USE_DLMALLOC && TURF_DLMALLOC_FAST_STATS
30         std::cout << "Population=" << population << ", inUse=" << TURF_HEAP.getInUseBytes() << std::endl;
31 #endif
32         for (; population < i * 5000; population++)
33             map.assign(population + 1, (void*) ((population << 2) | 3));
34     }
35
36     context.update();
37     context.unregisterThread();
38
39     return 0;
40 }