RapidXml 和内存池
使用 RapidXML,我需要创建和销毁大量 XML 节点和 XML 属性。我在内存池文档中读到,没有办法释放使用 allocate_string 函数在内存池中创建的单个字符串。
但通过这种方式,内存池的大小将会增加,在我看来,删除链接到不再使用的属性或节点的字符串时会出现问题。
我担心的是用一个过于动态的系统填充内存池空间,在这个系统中我创建和销毁了很多没有“先验”已知模式的节点。
有没有办法跳过这个问题?
添加:
阅读文档我发现了 memory_pool::set_allocator 函数,乍一看它似乎解决了我的问题。我尝试使用这个功能但没有成功。有人用过 set_allocator 函数吗?我没有在互联网上找到有关的示例或参考资料。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rapidxml 中的内存池不支持释放(除了释放整个池)。这是因为它们旨在在解析期间提供最大的分配性能,并且在这种情况下您不需要取消分配节点。
如果您需要手动分配和取消分配节点,没有什么可以阻止您使用 new/delete 从堆中分配节点。
set_allocator 函数在这里没有用处。它允许您替换整个池的分配机制,而不是单个节点的分配机制。
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.