1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <memory> 11 12 // allocator: 13 // pointer allocate(size_type n, allocator<void>::const_pointer hint=0); 14 15 #include <memory> 16 #include <cassert> 17 18 #include "count_new.hpp" 19 20 int A_constructed = 0; 21 22 struct A 23 { 24 int data; 25 A() {++A_constructed;} 26 A(const A&) {++A_constructed;} 27 ~A() {--A_constructed;} 28 }; 29 30 int main() 31 { 32 globalMemCounter.reset(); 33 std::allocator<A> a; 34 assert(globalMemCounter.checkOutstandingNewEq(0)); 35 assert(A_constructed == 0); 36 globalMemCounter.last_new_size = 0; 37 A* volatile ap = a.allocate(3); 38 assert(globalMemCounter.checkOutstandingNewEq(1)); 39 assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); 40 assert(A_constructed == 0); 41 a.deallocate(ap, 3); 42 assert(globalMemCounter.checkOutstandingNewEq(0)); 43 assert(A_constructed == 0); 44 45 globalMemCounter.last_new_size = 0; 46 A* volatile ap2 = a.allocate(3, (const void*)5); 47 assert(globalMemCounter.checkOutstandingNewEq(1)); 48 assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); 49 assert(A_constructed == 0); 50 a.deallocate(ap2, 3); 51 assert(globalMemCounter.checkOutstandingNewEq(0)); 52 assert(A_constructed == 0); 53 } 54