I'd like to use utility.library's splay tree functions. I've looked at them in the past and decided they weren't ideal at that time (probably lucky as looks like they were broken for ages), however I've now bothered to try them I've remembered why they weren't ideal...
What I need to be able to do is deallocate some resources when the tree is destroyed. I can't see any way of adding a callback when node are deleted, so this causes a big memory leak problem.
Is there any way to parse through an entire tree? I'd like to periodically trim the branches to avoid excessive memory usage.
If there's no way around these, I see btree.library would work, but it doesn't support splay trees (although a binary tree would still be better than what I have been using). Are there any other splay tree or similar implementations that are GPL or in an Amiga shared library that might be better for me?
Splay trees
- salass00
- AmigaOS Core Developer
- Posts: 530
- Joined: Sat Jun 18, 2011 3:12 pm
- Location: Finland
- Contact:
Re: Splay trees
Why not just use a memory pool for these allocations that you then free just after freeing the splay tree?chris wrote: What I need to be able to do is deallocate some resources when the tree is destroyed. I can't see any way of adding a callback when node are deleted, so this causes a big memory leak problem.
If the purpose is to remove nodes that haven't been accessed in a while you could use an LRU list for this.Is there any way to parse through an entire tree? I'd like to periodically trim the branches to avoid excessive memory usage.
https://github.com/salass00/ntfs-3g/blo ... playtree.cAre there any other splay tree or similar implementations that are GPL or in an Amiga shared library that might be better for me?
Re: Splay trees
It's not just plain memory, I have other pointers in my SplayNode which need freeing using other OS calls.salass00 wrote:Why not just use a memory pool for these allocations that you then free just after freeing the splay tree?chris wrote: What I need to be able to do is deallocate some resources when the tree is destroyed. I can't see any way of adding a callback when node are deleted, so this causes a big memory leak problem.
Sort of what I was doing anyway. I suppose I could keep the current list and use that to remove the nodes... should work.If the purpose is to remove nodes that haven't been accessed in a while you could use an LRU list for this.Is there any way to parse through an entire tree? I'd like to periodically trim the branches to avoid excessive memory usage.
[/quote]https://github.com/salass00/ntfs-3g/blo ... playtree.cAre there any other splay tree or similar implementations that are GPL or in an Amiga shared library that might be better for me?
That looks... actually identical to the one in utility.library, but at least I can modify it so that should solve the main problem, thanks.