-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest037.cc
More file actions
27 lines (26 loc) · 771 Bytes
/
Copy pathtest037.cc
File metadata and controls
27 lines (26 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "dmalloc.hh"
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cstdlib>
// heap_min and heap_max checking, more allocations.
int main() {
uintptr_t heap_min = 0;
uintptr_t heap_max = 0;
dmalloc_allocator<char> allocator;
for (int i = 0; i != 100; ++i) {
size_t sz = rand() % 100;
char* p = allocator.allocate(sz);
if (!heap_min || heap_min > (uintptr_t) p) {
heap_min = (uintptr_t) p;
}
if (!heap_max || heap_max < (uintptr_t) p + sz) {
heap_max = (uintptr_t) p + sz;
}
allocator.deallocate(p, sz);
}
dmalloc_statistics stat;
dmalloc_get_statistics(&stat);
assert(heap_min >= stat.heap_min);
assert(heap_max <= stat.heap_max);
}