TommyKaneko / Sketchup-API-C-Wrapper

A complete set of C++ Wrapper classes for SketchUp C API objects
MIT License
29 stars 8 forks source link

Question on SUStringRelease for a vector<SUStringRef> #36

Open jimfoltz opened 6 years ago

jimfoltz commented 6 years ago

https://github.com/TommyKaneko/Sketchup-API-C-Wrapper/blob/3f06f164448163b92bb12161bb694115899d056d/src/SUAPI-CppWrapper/model/RenderingOptions.cpp#L34

So this vector goes away at the end of the function call, correct? Does each element need SUStringRelease?

TommyKaneko commented 6 years ago

No, I don't believe so, as that ref 'becomes owned' by the String object on this line: https://github.com/TommyKaneko/Sketchup-API-C-Wrapper/blob/3f06f164448163b92bb12161bb694115899d056d/src/SUAPI-CppWrapper/model/RenderingOptions.cpp#L41

It would release the ref when the String object goes out of scope and destroys at the end of the function call.

thomthom commented 6 years ago

So all Ref objects passed into the wrapper makes the wrapper take ownership?

Side note: emplace_back can often be faster than push_back. With C++11 and newer it's generally the insertion method to reach for.

TommyKaneko commented 6 years ago

Mostly yes. Most wrapper constructors have an optional "attached" parameter when passing in a Ref object. This flag is held as a member variable, and indicates whether the ref object needs to be released on wrapper object destruction.

Will get into the habit of emplace_back - thanks for tip.