4 ms·
I like the way that Windows does it, where they have as the first element of the struct a double-word size (dwSize) element that records in 32-bits the size of
by c-linkage 3y ago
I like the way that Windows does it, where they have as the first element of the struct a double-word size (dwSize) element that records in 32-bits the size of the structure. The size essentially acts as a version identifier, as long as you never rearrange the fields and only append fields for new versions. The opaque functions test the value of the dwSize element to see what actions can be performed on the object.
The code that you develop can still access the member fields directly, and those accesses can be inlined and optimized aggressively by the compiler.
- bluejekyll 3y agoThis implies a branch statement in every function call, doesn’t it?
- veltas 3y agoThere's zero cost abstractions and then there's zero features abstractions.
- speed_spread 3y agoThe cost of that branch is insignificant next to that of the syscall you opted to make.