Comments (5)
Thank you for catching this. Changes committed. It is correct to be a virtual and public destructor, for polymorphism.
from sketchup-api-c-wrapper.
In this case, then maybe a protected non-virtual destructor is appropriate. Are there any usecases for creating any of these wrapper objects on the heap (using new
)? They are essentially opaque pointers over the SU API refs (which is again opaque pointers).
Adding virtual to this introduce the vtable, eating more memory per object. If these objects are only ever used without being allocated by new
- or to be more precise, without being deleted by a base pointer, then leaving it non-virtual but protected might be a more suitable option.
from sketchup-api-c-wrapper.
I have not found any use cases for creating wrapper objects on the heap using new
. However, if I make the destructor protected non-virtual, then I have issues with Temporary Objects, which I do use.
For example, this bit of code fails to compile when I have protected Entity destructor:
Entity RubyAPI::entity_from_ruby(const RUBY_VALUE& ruby_entity) {
SUEntityRef entity_ref = SU_INVALID;
SU_RESULT res = SUEntityFromRuby(ruby_entity, &entity_ref);
// ...Skip error checking....
return Entity(entity_ref, true); // Fails to compile as a temporary object needs to have a non-protected destructor.
}
I don't know as much as yourself about C++ @thomthom, but from what I understand the additional memory cost for the vtable is not large, and the additional memory is per class and not per object ( https://stackoverflow.com/questions/1626290/c-virtual-function-table-memory-cost ). There is an additional pointer per instance to the vtable however. If that is the case, I don't think it is something to worry about too much?
If there are ways to get around the temporary objects issue but use protected destructors, I'm certainly open to avoiding virtual methods.
from sketchup-api-c-wrapper.
hm... I don't see why a temporary needs a non-protected dtor. I'll have to have a closer look.
from sketchup-api-c-wrapper.
Do you have an example of issues with temporary objects when the dtor is protected?
from sketchup-api-c-wrapper.
Related Issues (20)
- Question about ctgmath and tgmath.h HOT 3
- Removing member variables of derived classes - single_member branch HOT 3
- Consider using a .editorconfig file HOT 4
- No Visual Studio / XCode project/solutions? HOT 13
- Test units - GoogleTest
- Type checking for TypedValue getters? HOT 6
- TypedValue::bool_value() HOT 4
- Question on SUStringRelease for a vector<SUStringRef> HOT 3
- String::std_string() returns null terminator as part of string. HOT 11
- Natviz for Wrapper objects HOT 2
- Expected behaviour of Radians roll-around? HOT 4
- Warnings: Returning address of local variable HOT 7
- Raise error level
- Editor Config with CMake? HOT 1
- CMake configuration for XCode HOT 6
- Reading TypedValue Arrays from a Model HOT 5
- When to check for validity of parameters, and when not to HOT 4
- Function that returns a list of all verticeswith their correct transforms. HOT 1
- [[maybe_unused]] an alternative to _unused HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sketchup-api-c-wrapper.