468,783 Members | 1,599 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

Trees without explicit memory management


Hello all,

I am creating arbitrary trees and would like to not have to deal with memory
management. The approach I've taken is to put each node in a std::list<>.
Obviously, the nodes will be deallocated when the list is destroyed or when
I call clear(). This approach works because my nodes can have simple
pointers to parent / children / siblings since the elements in a list never
move. Can anybody see any shortcomings in this approach or offer a superior
alternative?

Thanks,
Dave
Jul 22 '05 #1
1 1286
"Dave" <be***********@yahoo.com> wrote in
news:10*************@news.supernews.com:
I am creating arbitrary trees and would like to not have to deal with
memory management. The approach I've taken is to put each node in a
std::list<>. Obviously, the nodes will be deallocated when the list is
destroyed or when I call clear(). This approach works because my
nodes can have simple pointers to parent / children / siblings since
the elements in a list never move. Can anybody see any shortcomings
in this approach or offer a superior alternative?


You could use a deque as well -- if you know you won't need to remove
elements in the middle of the sequence. A list gives you flexibility to
unlink middle elements w/o risk of losing references though with a little
more memory overhead. Myself ended up using deques in a ternary search tree
implementation.

Cheers!
b
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Michael B. Allen | last post: by
3 posts views Thread by Dave | last post: by
14 posts views Thread by D. Alvarado | last post: by
9 posts views Thread by Mike P | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.