0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PageArenaAllocator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable 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
17  * along with Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
28 #ifndef HYPERTABLE_PAGEARENA_ALLOCATOR_H
29 #define HYPERTABLE_PAGEARENA_ALLOCATOR_H
30 
31 #include "PageArena.h"
32 #include "Allocator.h"
33 
34 namespace Hypertable {
35 
46 template <typename T, class ArenaT = PageArena<> >
47 struct PageArenaAllocator : public ArenaAllocatorBase<T, ArenaT> {
49  typedef typename Base::pointer pointer;
50  typedef typename Base::size_type size_type;
51 
52  template <typename U> struct rebind {
54  };
55 
57  PageArenaAllocator(ArenaT &arena) : Base(arena) {}
58 
60  template <typename U>
62  Base::set_arena(copy.arena());
63  }
64 
65  pointer allocate(size_type sz) {
67 
68  if (HT_LIKELY(Base::arena() != NULL))
69  return (pointer)(Base::arena()->alloc(sz * sizeof(T)));
70 
71  return Base::default_allocate(sz);
72  }
73 };
74 
77 } // namespace Hypertable
78 
79 #endif /* HYPERTABLE_PAGEARENA_ALLOCATOR_H */
Specialized Allocator class using a Memory Arena which manages the allocated memory; see PageArenaAll...
Definition: Allocator.h:159
PageArena memory allocator.
Memory Allocator base class.
PageArenaAllocator(const PageArenaAllocator< U, ArenaT > &copy)
Copy constructor.
The PageArenaAllocator is a STL allocator based on PageArena.
pointer default_allocate(size_type sz)
Allocate an array of objects using the regular operator new.
Definition: Allocator.h:199
ArenaAllocatorBase< T, ArenaT > Base
#define HT_LIKELY(x)
Definition: compat-c.h:69
void check_allocate_size(size_type sz) const
Sanity check the size of the requested buffer; if it's too large then most likely this is a bug in th...
Definition: Allocator.h:188
pointer allocate(size_type sz)
Hypertable definitions
void copy(TableDumper &, CellsBuilder &)
Definition: TableDumper.cc:129
PageArenaAllocator< U, ArenaT > other
ArenaT * arena() const
Returns a pointer to the Arena.
Definition: Allocator.h:246
void set_arena(ArenaT *arena)
Sets the Arena pointer.
Definition: Allocator.h:252