Unsolved Interfaces, abstract, concrete classes and QObject
-
I have to say, I'm enjoying it, not the flame, but the arguments, that's how we learn, experienced people discussing.
-
@kshegunov said in Interfaces, abstract, concrete classes and QObject:
allocating a void *, which is mighty inefficient
mighty = 32/64 bits of memory?
-
@VRonin said in Interfaces, abstract, concrete classes and QObject:
mighty = 32/64 bits of memory?
+ the heavy look-up through the heap manager. ;)
A stack (or more correctly auto-storage) allocation takes a single instruction for the whole of the memory. It basically increments (or rather decrements) the stack pointer with a single number.
PS. To expand a bit, think of it like this:
Allocating on the stack is one decrement of the stack pointer. Allocating an object with members with auto-storage on the heap is done in one go in the heap manager - one look up. If you allocate each of the members on the heap you go through so many look ups in the heap. -
I'm still convince that that "mighty" is nothing compared to the inefficiencies I unknowingly introduce in production code because I'm not smart enough to think the O(1) algorithm; but I have to admit I'm a total ignorant as this level of technicality
-
Well, I suppose that argument holds too ... :)
I've been known to run rampaging against the heap on occasion, plus arguably it shouldn't matter in most cases. I'm arguing the principles here however ... (sounding like the devil's advocate now)