This commit was manufactured by cvs2svn to create branch 'gomp-branch'.
[official-gcc.git] / libstdc++-v3 / testsuite / ext / pool_allocator / allocate_chunk.cc
blobab436212688bce6423bc82a7878d3fc3a467a655
1 // 2004-10-10 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2004 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 20.4.1.1 allocator members
23 #include <ext/pool_allocator.h>
25 struct small
27 char c[16];
30 struct big
32 char c[64];
35 void*
36 operator new(size_t n) throw(std::bad_alloc)
38 static bool first = true;
39 if (!first)
40 throw std::bad_alloc();
41 first = false;
42 return std::malloc(n);
45 // http://gcc.gnu.org/ml/libstdc++/2004-10/msg00098.html
46 void test01()
48 using __gnu_cxx::__pool_alloc;
50 __pool_alloc<big> alloc_big;
51 alloc_big.allocate(1);
53 // The constant 20 comes from __pool_alloc_base::_M_refill. See
54 // also __pool_alloc_base::_M_allocate_chunk.
55 __pool_alloc<small> alloc_small;
56 for (int i = 0; i < 20 * sizeof(big) / sizeof(small) + 1; ++i)
57 alloc_small.allocate(1);
60 int main()
62 test01();