2

Using RapidXML I need to create and destroy a lot of XML nodes and XML attributes. I read in memory pool documentation that there is not a way to free a single string created in memory pool with allocate_string function.

But in this way size of memory pool will increase and it seems to me a problem not succeed in deleting strings linked to attributes or nodes no more in use.

My fear is to fill memory pool space with a too dynamic system in which I create and destroy a lot of nodes without a "a-priori" known schema.

Is there a way to skip this problem?

Added:

Reading documentation I found the memory_pool::set_allocator function and at first glance it seems to solve my question. I tried to use this function but I didn't succeed. Did anyone ever used the set_allocator function? I didn't find examples or references about on internet.

user1052149
  • 39
  • 1
  • 5

1 Answers1

2

Memory pools in rapidxml do not support deallocation (other than freeing the entire pool). This is because they are designed to provide maximum allocation performance during parsing, and you don't need to deallocate nodes in this scenario.

If you need to manually allocate and deallocate nodes, nothing stops you from allocating nodes from the heap using new/delete.

set_allocator function will not be useful here. It allows you to replace allocation mechanism for the whole pool, not for individual nodes.

kaalus
  • 3,728
  • 3
  • 24
  • 34