AWS SDK for C++  1.8.7
AWS SDK for C++
AWSAllocator.h
Go to the documentation of this file.
1 
6 #pragma once
7 
9 
10 #include <aws/core/SDKConfig.h>
13 
14 #include <memory>
15 #include <cstdlib>
16 
17 namespace Aws
18 {
19 #ifdef USE_AWS_MEMORY_MANAGEMENT
20 
23  template <typename T>
24  class Allocator : public std::allocator<T>
25  {
26  public:
27 
28  typedef std::allocator<T> Base;
29 
30  Allocator() throw() :
31  Base()
32  {}
33 
34  Allocator(const Allocator<T>& a) throw() :
35  Base(a)
36  {}
37 
38  template <class U>
39  Allocator(const Allocator<U>& a) throw() :
40  Base(a)
41  {}
42 
43  ~Allocator() throw() {}
44 
45  typedef std::size_t size_type;
46 
47  template<typename U>
48  struct rebind
49  {
50  typedef Allocator<U> other;
51  };
52 
53  typename Base::pointer allocate(size_type n, const void *hint = nullptr)
54  {
56 
57  return reinterpret_cast<typename Base::pointer>(Malloc("AWSSTL", n * sizeof(T)));
58  }
59 
60  void deallocate(typename Base::pointer p, size_type n)
61  {
63 
64  Free(p);
65  }
66 
67  };
68 
69 #ifdef __ANDROID__
70 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0
71  template< typename T >
72  bool operator ==(const Allocator< T >& lhs, const Allocator< T >& rhs)
73  {
76 
77  return false;
78  }
79 #endif // _GLIBCXX_FULLY_DYNAMIC_STRING == 0
80 #endif // __ANDROID__
81 
82 #else
83 
84  template< typename T > using Allocator = std::allocator<T>;
85 
86 #endif // USE_AWS_MEMORY_MANAGEMENT
87 
91  template<typename T, typename ...ArgTypes>
92  std::shared_ptr<T> MakeShared(const char* allocationTag, ArgTypes&&... args)
93  {
94  AWS_UNREFERENCED_PARAM(allocationTag);
95 
96  return std::allocate_shared<T, Aws::Allocator<T>>(Aws::Allocator<T>(), std::forward<ArgTypes>(args)...);
97  }
98 
99 
100 } // namespace Aws
std::shared_ptr< T > MakeShared(const char *allocationTag, ArgTypes &&... args)
Definition: AWSAllocator.h:92
std::allocator< T > Allocator
Definition: AWSAllocator.h:84
#define AWS_UNREFERENCED_PARAM(x)
AWS_CORE_API void Free(void *memoryPtr)
AWS_CORE_API void * Malloc(const char *allocationTag, size_t allocationSize)