<p><a href="https://github.com/ChrisTrenkamp/goxpath/issues/6" rel="nofollow">Here's the backstory</a></p>
<p>Let's say I'm parsing a large XML file and building out the tree in memory. Eventually, it will start using up a lot of memory and it needs to be freed. However, I can't just release the memory, because if the user wants to go back up the tree, the data will be lost.</p>
<p>I need some kind of disk cache where I can dump parts of the tree and free some memory, but be able to retrieve that data again if it's needed. Does anyone know of a good library to use?</p>
<hr/>**评论:**<br/><br/>funny_falcon: <pre><p>First simple way is to use <a href="https://golang.org/pkg/encoding/gob/" rel="nofollow">https://golang.org/pkg/encoding/gob/</a> .
It has limitation of max size (if I remember correct, 256MB, or 1GB).
And it will deserialize whole tree on read.</p>
<p>Second simplet way is to use key-value storage.
You may use virtual node-ids instead of pointers:</p>
<pre><code> <xml>
<parent name="John">
<child sex="male" name="Bill">
<toy>Car</toy>
</child>
<child sex="female" name="Mary">
<toy>Barbie</toy>
</child>
</parent>
<xml>
</code></pre>
<p>Could be stored as (simplified form):</p>
<pre><code>'1$' : 'parent name="John"'
'1$cnt': '2'
'1$0001': '2'
'1$0002': '4'
'2$' : 'child sex="male" name="Bill"'
'2$cnt' : '1'
'2$0001' : '3'
'3$' : 'toy'
'3$cnt': '0'
'3$text': 'Car'
'4$' : 'child sex="female" name="Mary"'
'4$cnt' : '1'
'4$0001' : '5'
'5$' : 'toy'
'5$cnt': '0'
'5$text': 'Barbie'
</code></pre>
<p><a href="https://github.com/boltdb/bolt" rel="nofollow">https://github.com/boltdb/bolt</a></p>
<p><a href="https://github.com/cznic/kv" rel="nofollow">https://github.com/cznic/kv</a></p>
<p>BoltDB has "buckets", that could be nested to form tree. But it could be inefficient in term of space.</p>
<p>But if you want performance/space efficiency and laze retrieval (ie do not deserialize whole tree),
then you ought to build your own library.</p></pre>barsonme: <pre><p>Here's a read-only, disk-based radix tree: </p>
<p>github.com/sermodigital/drt</p>
<p>regardless of the route you go, mmap is your friend.</p></pre>__sahib__: <pre><p>Maybe <a href="https://github.com/boltdb/bolt" rel="nofollow">BoltDB</a> might be applicable here too. You can build hierarchies using buckets.
The database file is mmap()'d to memory.</p></pre>pmjtoca: <pre><p>I have been using lmdb for this type of requirements. robust and fast. lmdb is a C lib, good binding in Go exist (the gomp by msackman is my choice).</p></pre>Mythiix: <pre><p>I had trouble finding it. Link for others <a href="https://github.com/msackman/gomdb" rel="nofollow">https://github.com/msackman/gomdb</a></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传