Free Electron
StdAllocator.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __core_StdAllocator_h__
8 #define __core_StdAllocator_h__
9 
10 namespace fe
11 {
12 
13 /**************************************************************************//**
14  @brief Replacement for std::allocator using the FE memory system
15 
16 *//***************************************************************************/
17 template <class T>
19 {
20  public:
21  typedef FE_UWORD size_type;
22  typedef ptrdiff_t difference_type;
23  typedef T* pointer;
24  typedef const T* const_pointer;
25  typedef T& reference;
26  typedef const T& const_reference;
27  typedef T value_type;
28 
29  StdAllocator() {}
30  StdAllocator(const StdAllocator&) {}
31 
32  pointer allocate(size_type n, const void * = 0)
33  {
34  T* t = (T*) fe::allocate(n * sizeof(T));
35  feLog("StdAllocator::allocate %p\n",t);
36  return t;
37  }
38 
39  void deallocate(void* p, size_type)
40  {
41  if (p)
42  {
43 // feLog("StdAllocator::deallocate %p\n",p);
44  fe::deallocate(p);
45  }
46  }
47 
48  pointer address(reference x) const
49  { return &x; }
50 
51  const_pointer address(const_reference x) const
52  { return &x; }
53 
54  StdAllocator<T>& operator=(const StdAllocator&)
55  { return *this; }
56 
57  void construct(pointer p, const T& val)
58  { new ((T*) p) T(val); }
59 
60  void destroy(pointer p)
61  { p->~T(); }
62 
63  size_type max_size() const
64  { return FE_UWORD(-1); }
65 
66  template <class U>
67  struct rebind
68  { typedef StdAllocator<U> other; };
69 
70  template <class U>
71  StdAllocator(const StdAllocator<U>&) {}
72 
73  template <class U>
74  StdAllocator& operator=(const StdAllocator<U>&)
75  { return *this; }
76 };
77 
78 } /* namespace */
79 
80 #endif /* __core_StdAllocator_h__ */
81 
kernel
Definition: namespace.dox:3
Replacement for std::allocator using the FE memory system.
Definition: StdAllocator.h:18