handle-based objects vs pointer-based objets.

handle-based objects vs pointer-based objets.

Post by Boctor, Josep » Fri, 16 Feb 2001 10:33:13



What are the advantages of using of handle-based over pointer-based
objects in Memory allocation system?

thnx for any input
Joe

 
 
 

handle-based objects vs pointer-based objets.

Post by John Harriso » Sat, 17 Feb 2001 16:23:31


handle-based objects vs pointer-based objets.Please don't post HTML to a
newsgroup, plain text only.

The main advantage of handles is that the extra level of indirection means
that you can relocate the memory the handle points to without invalidating
the handle. The main disadvantage is that the extra level of indirection
means things are slower and because relocation is possible you often have to
make extra calls to lock and unlock the handle.

john


What are the advantages of using of handle-based over pointer-based objects
in Memory allocation system?
thnx for any input
Joe

 
 
 

handle-based objects vs pointer-based objets.

Post by Nick Hounsom » Sat, 17 Feb 2001 23:39:37



> What are the advantages of using of handle-based over pointer-based objects in
> Memory allocation system?

> thnx for any input
> Joe

If you only ever give out handles then you can be (reasonably) sure that they
aren't deleted incorrectly.  You can also do stuff like pooling, non-intrusive
statistics gathering and lazy construction. Also memory leaks are unlikely.

The absolute safest way to get the client to pass in a reference to a handle
(probably a nested class) that you fill in - this gives clear separation of
responsibility for ownership - the client creates and destroys handles using any
method it wants and your class creates and destroys the things handled via the
handle.