summaryrefslogtreecommitdiff
path: root/ACE/ace/Malloc_Base.h
diff options
context:
space:
mode:
authorAdam Mitz <mitza@ociweb.com>2015-11-06 17:07:11 -0600
committerAdam Mitz <mitza@ociweb.com>2015-11-06 17:07:11 -0600
commitac5e1702c9f9bee9f1f7bfce8c1a6f3847ea6b4b (patch)
tree0e70d1f51c39e688a05a6cdc2af58408222e4a0d /ACE/ace/Malloc_Base.h
parent5272b5b81f92c298cb998b5bb0b0dbca3e7f29fe (diff)
downloadATCD-ac5e1702c9f9bee9f1f7bfce8c1a6f3847ea6b4b.tar.gz
Merged branch ace-face-safety (FACE Safety Profile import from OCITAO).
Diffstat (limited to 'ACE/ace/Malloc_Base.h')
-rw-r--r--ACE/ace/Malloc_Base.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/ACE/ace/Malloc_Base.h b/ACE/ace/Malloc_Base.h
index b5be17807fb..b2690699226 100644
--- a/ACE/ace/Malloc_Base.h
+++ b/ACE/ace/Malloc_Base.h
@@ -22,6 +22,8 @@
#include "ace/os_include/sys/os_types.h"
#include "ace/os_include/sys/os_mman.h"
#include "ace/os_include/sys/os_types.h"
+#include <limits>
+#include <new>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
@@ -160,6 +162,71 @@ private:
static int delete_allocator_;
};
+/**
+ * @class ACE_Allocator_Std_Adapter
+ *
+ * @brief Model of std::allocator that forwards requests to
+# ACE_Allocator::instance. To be used with STL containers.
+ */
+
+template <typename T>
+class ACE_Export ACE_Allocator_Std_Adapter
+{
+public:
+ typedef T value_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ template <typename U> struct rebind { typedef ACE_Allocator_Std_Adapter<U> other; };
+
+ ACE_Allocator_Std_Adapter() {}
+
+ template <typename U>
+ ACE_Allocator_Std_Adapter(const ACE_Allocator_Std_Adapter<U>&) {}
+
+ static T* allocate(std::size_t n)
+ {
+ void* raw_mem = ACE_Allocator::instance()->malloc(n * sizeof(T));
+ if (!raw_mem) throw std::bad_alloc();
+ return static_cast<T*>(raw_mem);
+ }
+
+ static void deallocate(T* ptr, std::size_t)
+ {
+ ACE_Allocator::instance()->free(ptr);
+ }
+
+ static void construct(T* ptr, const T& value)
+ {
+ new (static_cast<void*>(ptr)) T(value);
+ }
+
+ static void destroy(T* ptr)
+ {
+ ptr->~T();
+ }
+
+ static size_type max_size()
+ {
+ return (std::numeric_limits<size_type>::max)();
+ }
+};
+
+template <typename T, typename U>
+bool operator==(const ACE_Allocator_Std_Adapter<T>&, const ACE_Allocator_Std_Adapter<U>&)
+{
+ return true;
+}
+
+template <typename T, typename U>
+bool operator!=(const ACE_Allocator_Std_Adapter<T>&, const ACE_Allocator_Std_Adapter<U>&)
+{
+ return false;
+}
+
ACE_END_VERSIONED_NAMESPACE_DECL
#include /**/ "ace/post.h"