From e305a07249fa8b772319d12f7657373cbb71173d Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Tue, 6 Jan 2009 13:14:13 +0000 Subject: Custom memory management functions implemented git-svn-id: http://pugixml.googlecode.com/svn/trunk@105 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/pugixml.hpp') diff --git a/src/pugixml.hpp b/src/pugixml.hpp index b1096fe..fd25077 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -1745,6 +1745,38 @@ namespace pugi */ std::wstring as_utf16(const char* str); #endif + + /** + * Memory allocation function + * + * \param size - allocation size + * \return pointer to allocated memory on success, NULL on failure + */ + typedef void* (*allocation_function)(size_t size); + + /** + * Memory deallocation function + * + * \param ptr - pointer to memory previously allocated by allocation function + */ + typedef void (*deallocation_function)(void* ptr); + + /** + * Override default memory management functions + * + * All subsequent allocations/deallocations will be performed via supplied functions. Take care not to + * change memory management functions if any xml_document instances are still alive - this is considered + * undefined behaviour (expect crashes/memory damages/etc.). + * + * \param allocate - allocation function + * \param deallocate - deallocation function + * + * \note XPath-related allocations, as well as allocations in functions that return std::string (xml_node::path, as_utf8, as_utf16) + * are not performed via these functions. + * \note If you're using parse() with ownership transfer, you have to allocate the buffer you pass to parse() with allocation + * function you set via this function. + */ + void set_memory_management_functions(allocation_function allocate, deallocation_function deallocate); } // Inline implementation -- cgit v1.2.3