]>
Commit | Line | Data |
---|---|---|
e55096f0 JK |
1 | // 2004-10-10 Paolo Carlini <pcarlini@suse.de> |
2 | ||
99dee823 | 3 | // Copyright (C) 2004-2021 Free Software Foundation, Inc. |
e55096f0 JK |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
e55096f0 JK |
9 | // any later version. |
10 | // | |
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. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
e55096f0 JK |
19 | |
20 | // 20.4.1.1 allocator members | |
21 | ||
22 | #include <ext/pool_allocator.h> | |
1f153a1d | 23 | #include <testsuite_hooks.h> |
e55096f0 JK |
24 | |
25 | struct small | |
26 | { | |
27 | char c[16]; | |
28 | }; | |
29 | ||
30 | struct big | |
31 | { | |
32 | char c[64]; | |
33 | }; | |
34 | ||
35 | void* | |
1f153a1d | 36 | operator new(size_t n) THROW(std::bad_alloc) |
e55096f0 JK |
37 | { |
38 | static bool first = true; | |
39 | if (!first) | |
40 | throw std::bad_alloc(); | |
41 | first = false; | |
42 | return std::malloc(n); | |
43 | } | |
44 | ||
45 | // http://gcc.gnu.org/ml/libstdc++/2004-10/msg00098.html | |
46 | void test01() | |
47 | { | |
48 | using __gnu_cxx::__pool_alloc; | |
49 | ||
50 | __pool_alloc<big> alloc_big; | |
2104ca71 | 51 | (void) alloc_big.allocate(1); |
e55096f0 JK |
52 | |
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; | |
8b5bc374 | 56 | for (unsigned int i = 0; i < 20 * sizeof(big) / sizeof(small) + 1; ++i) |
2104ca71 | 57 | (void) alloc_small.allocate(1); |
e55096f0 JK |
58 | } |
59 | ||
60 | int main() | |
61 | { | |
62 | test01(); | |
63 | } |