my question style/structure in apple's objective-c headers. take nssplitviewitem
, example:
nssplitviewitem (apple):
@interface nssplitviewitem : nsobject { @private id _splitviewitemprivatedata; struct { unsigned int _collapsed:1; unsigned int _cancollapsefromdrag:1; unsigned int _cancollapsefromdoubleclickondivider:1; unsigned int _reserved:29; } _flags; }
why struct?
why apple seem favor using struct of int
flags options? pattern incredibly common throughout headers, in places seems unnecessary—such here. why not put ints
ivars on class rather wrap them struct?
is there performance gain or other benefit? here, "flags" related "collapasing". in other classes, such nstableview
, there "flags" structs have more 2 dozen unrelated entries.
so apple style, or there more meaningful?
they using bit fields. in case, means 3 values stored in 32 bits. plus future extension, can add 29 more boolean variables in same 32 bits, without changing layout of structure. if data persisted, adding these 29 further variables doesn't require change in version number.
if have 2 dozen unrelated values, that's 2 dozen values stored in 32 bits = 4 byte. helps memory usage.
Comments
Post a Comment