From a58131c9dc30b38f0e7271a8b0309915ce559c3a Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine@gmail.com" Date: Wed, 14 Mar 2012 06:04:50 +0000 Subject: Added PUGIXML_MEMORY constants for tweaking memory behaviour; useful for embedded systems or for unusual cases (i.e. thousands of small documents in memory) git-svn-id: http://pugixml.googlecode.com/svn/trunk@860 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugiconfig.hpp | 5 +++++ src/pugixml.cpp | 29 ++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/pugiconfig.hpp b/src/pugiconfig.hpp index 8842180..465fd21 100644 --- a/src/pugiconfig.hpp +++ b/src/pugiconfig.hpp @@ -36,6 +36,11 @@ // #define PUGIXML_HEADER_ONLY // #include "pugixml.cpp" +// Tune these constants to adjust memory-related behavior +// #define PUGIXML_MEMORY_PAGE_SIZE 32768 +// #define PUGIXML_MEMORY_OUTPUT_STACK 10240 +// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096 + #endif /** diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 572576b..c56135b 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -225,7 +225,13 @@ PUGI__NS_END #endif PUGI__NS_BEGIN - static const size_t xml_memory_page_size = 32768; + static const size_t xml_memory_page_size = + #ifdef PUGIXML_MEMORY_PAGE_SIZE + PUGIXML_MEMORY_PAGE_SIZE + #else + 32768 + #endif + ; static const uintptr_t xml_memory_page_alignment = 32; static const uintptr_t xml_memory_page_pointer_mask = ~(xml_memory_page_alignment - 1); @@ -2803,6 +2809,7 @@ PUGI__NS_BEGIN public: xml_buffered_writer(xml_writer& writer_, xml_encoding user_encoding): writer(writer_), bufsize(0), encoding(get_write_encoding(user_encoding)) { + PUGI__STATIC_ASSERT(bufcapacity >= 8); } ~xml_buffered_writer() @@ -2946,7 +2953,17 @@ PUGI__NS_BEGIN // utf8 maximum expansion: x4 (-> utf32) // utf16 maximum expansion: x2 (-> utf32) // utf32 maximum expansion: x1 - enum { bufcapacity = 2048 }; + enum + { + bufcapacitybytes = + #ifdef PUGIXML_MEMORY_OUTPUT_STACK + PUGIXML_MEMORY_OUTPUT_STACK + #else + 10240 + #endif + , + bufcapacity = bufcapacitybytes / (sizeof(char_t) + 4) + }; char_t buffer[bufcapacity]; char scratch[4 * bufcapacity]; @@ -5337,7 +5354,13 @@ PUGI__NS_BEGIN { xpath_memory_block* next; - char data[4096]; + char data[ + #ifdef PUGIXML_MEMORY_XPATH_PAGE_SIZE + PUGIXML_MEMORY_XPATH_PAGE_SIZE + #else + 4096 + #endif + ]; }; class xpath_allocator -- cgit v1.2.3