OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [ext/] [pool_allocator/] [allocate_chunk.cc] - Blame information for rev 749

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// 2004-10-10  Paolo Carlini  <pcarlini@suse.de>
2
 
3
// Copyright (C) 2004, 2009 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
 
20
// 20.4.1.1 allocator members
21
 
22
#include <ext/pool_allocator.h>
23
 
24
struct small
25
{
26
  char c[16];
27
};
28
 
29
struct big
30
{
31
  char c[64];
32
};
33
 
34
void*
35
operator new(size_t n) throw(std::bad_alloc)
36
{
37
  static bool first = true;
38
  if (!first)
39
    throw std::bad_alloc();
40
  first = false;
41
  return std::malloc(n);
42
}
43
 
44
// http://gcc.gnu.org/ml/libstdc++/2004-10/msg00098.html
45
void test01()
46
{
47
  using __gnu_cxx::__pool_alloc;
48
 
49
  __pool_alloc<big> alloc_big;
50
  alloc_big.allocate(1);
51
 
52
  // The constant 20 comes from __pool_alloc_base::_M_refill. See
53
  // also __pool_alloc_base::_M_allocate_chunk.
54
  __pool_alloc<small> alloc_small;
55
  for (unsigned int i = 0; i < 20 * sizeof(big) / sizeof(small) + 1; ++i)
56
    alloc_small.allocate(1);
57
}
58
 
59
int main()
60
{
61
  test01();
62
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.