V8 Project
zone-allocator.h
Go to the documentation of this file.
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_ZONE_ALLOCATOR_H_
6 #define V8_ZONE_ALLOCATOR_H_
7 
8 #include <limits>
9 
10 #include "src/zone.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 template<typename T>
17  public:
18  typedef T* pointer;
19  typedef const T* const_pointer;
20  typedef T& reference;
21  typedef const T& const_reference;
22  typedef T value_type;
23  typedef size_t size_type;
24  typedef ptrdiff_t difference_type;
25  template<class O> struct rebind {
27  };
28 
29  explicit zone_allocator(Zone* zone) throw() : zone_(zone) {}
30  explicit zone_allocator(const zone_allocator& other) throw()
31  : zone_(other.zone_) {}
32  template<typename U> zone_allocator(const zone_allocator<U>& other) throw()
33  : zone_(other.zone_) {}
34  template<typename U> friend class zone_allocator;
35 
36  pointer address(reference x) const {return &x;}
37  const_pointer address(const_reference x) const {return &x;}
38 
39  pointer allocate(size_type n, const void* hint = 0) {
40  return static_cast<pointer>(zone_->NewArray<value_type>(
41  static_cast<int>(n)));
42  }
43  void deallocate(pointer p, size_type) { /* noop for Zones */ }
44 
45  size_type max_size() const throw() {
46  return std::numeric_limits<int>::max() / sizeof(value_type);
47  }
48  void construct(pointer p, const T& val) {
49  new(static_cast<void*>(p)) T(val);
50  }
51  void destroy(pointer p) { p->~T(); }
52 
53  bool operator==(zone_allocator const& other) {
54  return zone_ == other.zone_;
55  }
56  bool operator!=(zone_allocator const& other) {
57  return zone_ != other.zone_;
58  }
59 
60  private:
63 };
64 
67 } } // namespace v8::internal
68 
69 #endif // V8_ZONE_ALLOCATOR_H_
T * NewArray(int length)
Definition: zone.h:46
const_pointer address(const_reference x) const
pointer address(reference x) const
void construct(pointer p, const T &val)
zone_allocator(const zone_allocator &other)
bool operator!=(zone_allocator const &other)
zone_allocator(const zone_allocator< U > &other)
bool operator==(zone_allocator const &other)
void deallocate(pointer p, size_type)
size_type max_size() const
pointer allocate(size_type n, const void *hint=0)
zone_allocator< int > ZoneIntAllocator
zone_allocator< bool > ZoneBoolAllocator
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
#define T(name, string, precedence)
Definition: token.cc:25