aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/allocator.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'libxsde/xsde/cxx/allocator.hxx')
-rw-r--r--libxsde/xsde/cxx/allocator.hxx49
1 files changed, 49 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/allocator.hxx b/libxsde/xsde/cxx/allocator.hxx
new file mode 100644
index 0000000..248ee55
--- /dev/null
+++ b/libxsde/xsde/cxx/allocator.hxx
@@ -0,0 +1,49 @@
+// file : xsde/cxx/allocator.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSDE_CXX_ALLOCATOR_HXX
+#define XSDE_CXX_ALLOCATOR_HXX
+
+#include <stddef.h> // size_t
+#include <new> // placement new
+
+#include <xsde/cxx/config.hxx>
+
+namespace xsde
+{
+ namespace cxx
+ {
+ // Allocate a memory block using custom allocator. If exceptions
+ // are enabled this function throws std::bad_alloc on failure.
+ // Otherwise it returns 0.
+ //
+ void*
+ alloc (size_t);
+
+ void
+ free (void*);
+
+#ifdef XSDE_EXCEPTIONS
+ struct alloc_guard
+ {
+ alloc_guard (void* p) : p_ (p) {}
+ ~alloc_guard () { if (p_) cxx::free (p_); }
+
+ void*
+ get () const { return p_; }
+
+ void
+ release () { p_ = 0; }
+
+ private:
+ void* p_;
+ };
+#endif
+ }
+}
+
+#include <xsde/cxx/allocator.ixx>
+
+#endif // XSDE_CXX_ALLOCATOR_HXX