summaryrefslogtreecommitdiff
path: root/docs/manual.qbk
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-06-24 12:28:17 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-06-24 12:28:17 +0000
commit3117219e7c343645d7cb3d3c19fbc6a126522695 (patch)
tree274e9a5508aae06e72602b663f08b1cae720c5cc /docs/manual.qbk
parent8d6177ebd8d7cc54839d80525936aa76746e4d33 (diff)
docs: Extracted sample code in a separate file, added stream loading sample prototype
git-svn-id: http://pugixml.googlecode.com/svn/trunk@534 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'docs/manual.qbk')
-rw-r--r--docs/manual.qbk21
1 files changed, 5 insertions, 16 deletions
diff --git a/docs/manual.qbk b/docs/manual.qbk
index 8b3bea6..5668906 100644
--- a/docs/manual.qbk
+++ b/docs/manual.qbk
@@ -375,22 +375,11 @@ You can use the following accessor functions to change or get current memory man
Allocation function is called with the size (in bytes) as an argument and should return a pointer to memory block with alignment that is suitable for pointer storage and size that is greater or equal to the requested one. If the allocation fails, the function has to return null pointer (throwing an exception from allocation function results in undefined behavior). Deallocation function is called with the pointer that was returned by the previous call or with a null pointer; null pointer deallocation should be handled as a no-op. If memory management functions are not thread-safe, library thread safety is not guaranteed.
-This is a simple example of custom memory management:
-
- void* custom_allocate(size_t size)
- {
- return new (std::nothrow) char[size];
- }
-
- void custom_deallocate(void* ptr)
- {
- delete[] static_cast<char*>(ptr);
- }
-
- int main()
- {
- pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
- }
+This is a simple example of custom memory management ([@samples/custom_memory_management.cpp])
+
+[import samples/custom_memory_management.cpp]
+[code_custom_memory_management_decl]
+[code_custom_memory_management_call]
When setting new memory management functions, care must be taken to make sure that there are no live pugixml objects. Otherwise when the objects are destroyed, the new deallocation function will be called with the memory obtained by the old allocation function, resulting in undefined behavior.