Skip to content

Handle vs SharedPointer #560

Closed Answered by dpasukhi
petrasvestartas asked this question in Q&A
Discussion options

You must be logged in to vote

The difference between OpenCascade's Handle and C++'s std::shared_ptr is similar to the difference between std::shared_ptr and boost::intrusive_ptr.

Key differences:

  1. Intrusive vs. Non-intrusive Reference Counting:

    • Handle<T> is intrusive - the reference count is stored in the object itself
    • std::shared_ptr is non-intrusive - the reference count is stored separately from the object
  2. Object Requirements:

    • Handle<T> requires objects to inherit from Standard_Transient
    • std::shared_ptr can wrap any object
  3. Memory Layout:

    • Handle<T> has less overhead since the reference count is inside the object
    • std::shared_ptr has more overhead (typically two pointers - one to the object and one to the co…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@petrasvestartas
Comment options

@dpasukhi
Comment options

@petrasvestartas
Comment options

Answer selected by dpasukhi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants