From 2e501c68a8641a2b3c430b55f13491a9c1c5d0f5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 11 May 2010 12:20:11 +0200 Subject: Add support for custom allocators New example: examples/cxx/hybrid/allocator. --- libxsde/xsde/cxx/hybrid/xdr/istream.cxx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'libxsde/xsde/cxx/hybrid/xdr/istream.cxx') diff --git a/libxsde/xsde/cxx/hybrid/xdr/istream.cxx b/libxsde/xsde/cxx/hybrid/xdr/istream.cxx index 2f870d0..e31fb7f 100644 --- a/libxsde/xsde/cxx/hybrid/xdr/istream.cxx +++ b/libxsde/xsde/cxx/hybrid/xdr/istream.cxx @@ -23,7 +23,7 @@ namespace xsde throw xdr_exception (); x.clear (); - + if (n != 0) { x.resize (n); @@ -42,11 +42,19 @@ namespace xsde if (!xdr_u_int (&xdr_, &n)) throw xdr_exception (); +#ifndef XSDE_CUSTOM_ALLOCATOR x = new char[n + 1]; +#else + x = static_cast (alloc (n + 1)); +#endif if (!xdr_opaque (&xdr_, x, n)) { +#ifndef XSDE_CUSTOM_ALLOCATOR delete[] x; +#else + cxx::free (x); +#endif throw xdr_exception (); } @@ -80,14 +88,14 @@ namespace xsde return false; x.clear (); - + if (n != 0) { x.resize (n); char* p = const_cast (x.c_str ()); return xdr_opaque (&xdr_, p, n); } - + return true; } #else @@ -99,14 +107,21 @@ namespace xsde if (!xdr_u_int (&xdr_, &n)) return false; +#ifndef XSDE_CUSTOM_ALLOCATOR x = new char[n + 1]; - +#else + x = static_cast (alloc (n + 1)); +#endif if (x == 0) return false; if (!xdr_opaque (&xdr_, x, n)) { +#ifndef XSDE_CUSTOM_ALLOCATOR delete[] x; +#else + cxx::free (x); +#endif return false; } -- cgit v1.1