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
This commit is contained in:
arseny.kapoulkine@gmail.com 2012-03-14 06:04:50 +00:00
parent 35ea9a6088
commit a58131c9dc
2 changed files with 31 additions and 3 deletions

View File

@ -36,6 +36,11 @@
// #define PUGIXML_HEADER_ONLY // #define PUGIXML_HEADER_ONLY
// #include "pugixml.cpp" // #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 #endif
/** /**

View File

@ -225,7 +225,13 @@ PUGI__NS_END
#endif #endif
PUGI__NS_BEGIN 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_alignment = 32;
static const uintptr_t xml_memory_page_pointer_mask = ~(xml_memory_page_alignment - 1); static const uintptr_t xml_memory_page_pointer_mask = ~(xml_memory_page_alignment - 1);
@ -2803,6 +2809,7 @@ PUGI__NS_BEGIN
public: public:
xml_buffered_writer(xml_writer& writer_, xml_encoding user_encoding): writer(writer_), bufsize(0), encoding(get_write_encoding(user_encoding)) 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() ~xml_buffered_writer()
@ -2946,7 +2953,17 @@ PUGI__NS_BEGIN
// utf8 maximum expansion: x4 (-> utf32) // utf8 maximum expansion: x4 (-> utf32)
// utf16 maximum expansion: x2 (-> utf32) // utf16 maximum expansion: x2 (-> utf32)
// utf32 maximum expansion: x1 // 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_t buffer[bufcapacity];
char scratch[4 * bufcapacity]; char scratch[4 * bufcapacity];
@ -5337,7 +5354,13 @@ PUGI__NS_BEGIN
{ {
xpath_memory_block* next; 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 class xpath_allocator