Lockless Task Scheduler  v1.0a
A lockless task scheduler
allocator.h
1 // ***********************************************************************
2 // Assembly : task_scheduler
3 // Author : viknash
4 // ***********************************************************************
5 // <copyright file="allocator.h" >
6 // Copyright (c) viknash. All rights reserved.
7 // </copyright>
8 // <summary></summary>
9 // ***********************************************************************
10 #pragma once
11 
16 namespace task_scheduler {
17  template < class T, class TMemInterface > class stl_allocator : public TMemInterface
18  {
19  public:
20  // typedefs
21  typedef T value_type;
22  typedef value_type *pointer;
23  typedef const value_type *const_pointer;
24  typedef value_type &reference;
25  typedef const value_type &const_reference;
26  typedef size_t size_type;
27  typedef ptrdiff_t difference_type;
28 
29  public:
30  // convert an allocator<T> to allocator<U>
31 
35  template < typename U, class TMemInterface > struct rebind
36  {
38  };
39 
40  public:
44  inline stl_allocator() {}
48  inline ~stl_allocator() {}
53  inline stl_allocator(stl_allocator const &) {}
58  template < typename U > inline stl_allocator(stl_allocator< U, TMemInterface > const &) {}
59 
65  inline pointer address(reference r) { return &r; }
71  inline const_pointer address(const_reference r) { return &r; }
72 
79  inline pointer allocate(size_type _cnt, typename std::allocator< void >::const_pointer = 0)
80  {
81  pointer new_memory = reinterpret_cast<pointer>(operator new(_cnt * sizeof(T)));
82  return new_memory;
83  }
84 
90  inline void deallocate(pointer _p, size_type _n) { operator delete(_p, _n * sizeof(T)); }
91 
96  inline size_type max_size() const { return std::numeric_limits< size_type >::max() / sizeof(T); }
97 
103  inline bool operator==(stl_allocator const &) const { return true; }
104 
110  inline bool operator!=(stl_allocator const &_a) { return !operator==(_a); }
111  };
112 }
stl_allocator(stl_allocator const &)
Initializes a new instance of the stl_allocator class.
Definition: allocator.h:53
bool operator==(stl_allocator const &) const
Operator==s the specified .
Definition: allocator.h:103
Class stl_allocator.
Definition: allocator.h:16
Struct rebind
Definition: allocator.h:35
size_type max_size() const
Maximums the size.
Definition: allocator.h:96
Definition: allocator.h:17
stl_allocator()
Initializes a new instance of the stl_allocator class.
Definition: allocator.h:44
pointer allocate(size_type _cnt, typename std::allocator< void >::const_pointer=0)
Allocates the specified count.
Definition: allocator.h:79
const_pointer address(const_reference r)
Addresses the specified r.
Definition: allocator.h:71
stl_allocator(stl_allocator< U, TMemInterface > const &)
Initializes a new instance of the stl_allocator class.
Definition: allocator.h:58
pointer address(reference r)
Addresses the specified r.
Definition: allocator.h:65
void deallocate(pointer _p, size_type _n)
Deallocates the specified p.
Definition: allocator.h:90
bool operator!=(stl_allocator const &_a)
Operator!=s the specified a.
Definition: allocator.h:110
~stl_allocator()
Finalizes an instance of the stl_allocator class.
Definition: allocator.h:48