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