aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hashmap.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-05-11 12:20:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-05-11 12:20:11 +0200
commit2e501c68a8641a2b3c430b55f13491a9c1c5d0f5 (patch)
tree49c2748443fe3c1f01108756b647440e0647a11b /libxsde/xsde/cxx/hashmap.cxx
parent161beba6cdb0d91b15ad19fa8b3e51d986203915 (diff)
Add support for custom allocators
New example: examples/cxx/hybrid/allocator.
Diffstat (limited to 'libxsde/xsde/cxx/hashmap.cxx')
-rw-r--r--libxsde/xsde/cxx/hashmap.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/hashmap.cxx b/libxsde/xsde/cxx/hashmap.cxx
index b633cbd..f87ebbf 100644
--- a/libxsde/xsde/cxx/hashmap.cxx
+++ b/libxsde/xsde/cxx/hashmap.cxx
@@ -7,6 +7,10 @@
#include <xsde/cxx/hashmap.hxx>
+#ifdef XSDE_CUSTOM_ALLOCATOR
+# include <xsde/cxx/allocator.hxx>
+#endif
+
namespace xsde
{
namespace cxx
@@ -76,10 +80,18 @@ namespace xsde
for (size_t i = 0; i < bcount_; ++i)
{
if (buckets_[i])
+#ifndef XSDE_CUSTOM_ALLOCATOR
operator delete (buckets_[i]);
+#else
+ cxx::free (buckets_[i]);
+#endif
}
+#ifndef XSDE_CUSTOM_ALLOCATOR
delete[] buckets_;
+#else
+ cxx::free (buckets_); // POD.
+#endif
#ifndef XSDE_EXCEPTIONS
}
@@ -95,7 +107,11 @@ namespace xsde
error_ = error_none;
#endif
+#ifndef XSDE_CUSTOM_ALLOCATOR
buckets_ = new bucket*[bcount_];
+#else
+ buckets_ = static_cast<bucket**> (alloc (bcount_ * sizeof (bucket*)));
+#endif
#ifndef XSDE_EXCEPTIONS
if (buckets_ == 0)
@@ -118,8 +134,13 @@ namespace xsde
// No elements in this bucket yet. Start with capacity for 2
// elements.
//
+#ifndef XSDE_CUSTOM_ALLOCATOR
p = static_cast<bucket*> (
operator new (sizeof (bucket) + 2 * (sizeof (element) + esize_)));
+#else
+ p = static_cast<bucket*> (
+ alloc (sizeof (bucket) + 2 * (sizeof (element) + esize_)));
+#endif
#ifndef XSDE_EXCEPTIONS
if (p == 0)
@@ -137,8 +158,14 @@ namespace xsde
// No more space in this bucket. Create a bigger bucket.
//
size_t c = p->size_ * 2;
+
+#ifndef XSDE_CUSTOM_ALLOCATOR
bucket* n = static_cast<bucket*> (
operator new (sizeof (bucket) + c * (sizeof (element) + esize_)));
+#else
+ bucket* n = static_cast<bucket*> (
+ alloc (sizeof (bucket) + c * (sizeof (element) + esize_)));
+#endif
#ifndef XSDE_EXCEPTIONS
if (n == 0)
@@ -155,7 +182,11 @@ namespace xsde
memcpy (dst, src, p->size_ * (sizeof (element) + esize_));
+#ifndef XSDE_CUSTOM_ALLOCATOR
operator delete (p);
+#else
+ cxx::free (p);
+#endif
p = n;
}