]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/ext/mt_allocator/tune-2.cc
re PR libstdc++/16614 (Excessive resource usage in __mt_alloc)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / mt_allocator / tune-2.cc
CommitLineData
8bfd0a46
BK
1// 2004-08-25 Benjamin Kosnik <bkoz@redhat.com>
2//
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.
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
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.
20
21#include <cassert>
22#include <memory>
23#include <ext/mt_allocator.h>
24
25struct pod
26{
27 int i;
28};
29
30// Tune characteristics.
31// __per_type_pool_policy
32void test02()
33{
34 typedef pod value_type;
35#ifdef __GTHREADS
36 typedef __gnu_cxx::__per_type_pool_policy<value_type, true> policy_type;
37#else
38 typedef __gnu_cxx::__per_type_pool_policy<value_type, false> policy_type;
39#endif
40 typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
41 typedef __gnu_cxx::__pool_base::_Tune tune_type;
42
43 tune_type t_default;
44 tune_type t_opt(16, 5120, 32, 5120, 20, 10, false);
45 tune_type t_single(16, 5120, 32, 5120, 1, 10, false);
46
47 allocator_type a;
48 tune_type t1 = a._M_get_options();
49 assert(t1._M_align == t_default._M_align);
50 a._M_set_options(t_opt);
51 tune_type t2 = a._M_get_options();
52 assert(t1._M_align != t2._M_align);
53
54 allocator_type::pointer p1 = a.allocate(128);
55 allocator_type::pointer p2 = a.allocate(5128);
56 a._M_set_options(t_single);
57 t1 = a._M_get_options();
58 assert(t1._M_max_threads != t_single._M_max_threads);
59 assert(t1._M_max_threads == t_opt._M_max_threads);
60
61 a.deallocate(p1, 128);
62 a.deallocate(p2, 5128);
63}
64
65
66int main()
67{
68 test02();
69
70 return 0;
71}