Retrieving attribute (TopoDS_shape) by reference from the Handle(TDocStd_Document) doc?

I have an TopoDS_Shape attribute in a label of the document{Handle(TDocStd_Document) doc}.
when the document is in session, I use the following code to retrieve it

Handle(TNaming_NamedShape) attrib;
m_root.FindAttribute(TNaming_NamedShape::GetID(), attrib)
attrib->Get(); //Get() returns by value

will this create a duplicate of the TopoDS_shape attribute as it returns by value? If yes then my memory cannot handle 2 large TopoDS_shapes,
is it possible to get a reference to the TopoDS_ Shape attribute from document to avoid duplication?

Kirill Gavrilov's picture

TopoDS_ Shape is a special class in OCCT implementing an implicit smart-pointer behavior. This class stores a combination of Handle(TopoDS_ TShape), TopLoc_Location and Orientation flag. So that making a simple TopoDS_ Shape copy via C++ assignment wouldn't duplicate an underlying geometry - it will keep a reference to it. No worry in memory usage explosion here.

Mikhail MPV's picture

  Dear Kavin,

TopoDS_Shape is just a simple interface, similar to smart pointer. The large data of the shape is concealed inside, in TopoDS_TShape and don't copied in this case.

Also, IsEqual method for two shapes created by two "Get" calls will return true.



Kavin Prasad's picture

Thanks Mikhail and thanks Kirill Gavrilov, it helped a lot