3 ms·
const type field in the base class, non-virtual accessor (direct field access can be inlined). Memory vs CPU, the usual trade off.
by jonhohle 9y ago
const type field in the base class, non-virtual accessor (direct field access can be inlined). Memory vs CPU, the usual trade off.
- euyyn 9y agoIt wouldn't cost memory though, because you free up a slot in the virtual table. No?
- jonhohle 9y agoVirtual table should be one per class. A type field would be once per instance.
- euyyn 9y agoAh, right, static fields in C++ can't be overridden. If they could, they could be implemented by stuffing them in the virtual table and the cost in space would be O(classes) instead of O(instances).
- deleted 9y ago[deleted]