c++ - Handles vs Smart pointers. What to use? -



c++ - Handles vs Smart pointers. What to use? -

i'm starting develop graphical engine practicing purposes. 1 of first questions arised either utilize handles or smart pointers refer class instances.

from point of view:

smart pointers pros: created under demand, not have problem of becoming stale pointers; cons: in linked list, searching pointer o(n) operation.

handles pros: search o(1), object relocation o(1); cons: can became stale pointers, creating new handle forces scheme check first null entry in handles table.

which 1 choose? please explain selection.

edited:

i want clarify points after comments , answers.

i don't mean smart pointers linked list in way of "are represented stl linked list". mean behave, in way linked list (if move 1 object 1 memory block another, need iterate total list of smart pointers update references object -it can done linked list -).

and don't mean handles opaque pointers or pointer implementation models. mean having global handle table (an array of pointers) when request object, dereferenceable instance containing index in table actual pointer object can found. so, if move object 1 block another, updating pointer entry in handle table pointers automatically updated @ same time.

neither of definitions fit what's used. smart pointers aren't in linked-list in way @ all. utilize observer pattern maintain vector of raw pointers objects still exist if need iterate them or something. handles describe them pretty much used binary compatibility reasons , never in-process.

use smart pointers, take care of themselves.

c++ handle smart-pointers

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -