tune-2.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // 2004-08-25 Benjamin Kosnik <bkoz@redhat.com>
  2. //
  3. // Copyright (C) 2004-2022 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 3, 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 COPYING3. If not see
  18. // <http://www.gnu.org/licenses/>.
  19. #include <memory>
  20. #include <ext/mt_allocator.h>
  21. #include <testsuite_hooks.h>
  22. #include <testsuite_character.h>
  23. #ifdef __GTHREADS
  24. #define __cxxthread true
  25. #else
  26. #define __cxxthread false
  27. #endif
  28. // Tune characteristics.
  29. // __per_type_pool_policy
  30. void test02()
  31. {
  32. typedef __gnu_test::pod_int value_type;
  33. using __gnu_cxx::__pool;
  34. using __gnu_cxx::__per_type_pool_policy;
  35. typedef __per_type_pool_policy<value_type, __pool, __cxxthread> policy_type;
  36. typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
  37. typedef __gnu_cxx::__pool_base::_Tune tune_type;
  38. allocator_type a;
  39. tune_type t_default = a._M_get_options();
  40. tune_type t_opt(32, 5120, 32, 5120, 20, 10, false);
  41. tune_type t_small(16, 1024, 32, 2048, 1, 10, false);
  42. tune_type t1 = t_default;
  43. a._M_set_options(t_opt);
  44. tune_type t2 = a._M_get_options();
  45. VERIFY( t1._M_align != t2._M_align );
  46. allocator_type::pointer p1 = a.allocate(128);
  47. allocator_type::pointer p2 = a.allocate(5128);
  48. a._M_set_options(t_small);
  49. tune_type t3 = a._M_get_options();
  50. VERIFY( t3._M_chunk_size != t_small._M_chunk_size );
  51. VERIFY( t3._M_chunk_size == t_opt._M_chunk_size );
  52. a.deallocate(p1, 128);
  53. a.deallocate(p2, 5128);
  54. }
  55. int main()
  56. {
  57. test02();
  58. return 0;
  59. }