BitArray/BitFields - Review

Era Scarecrow rtcvb32 at yahoo.com
Sun Jul 29 05:39:11 PDT 2012


On Sunday, 29 July 2012 at 09:30:06 UTC, Dmitry Olshansky wrote:
> I have simpler suggestion. Maybe doing it as 2 containers:
>
> BitSet is a plain value type with small array optimization 
> (what you called BitArray in last 2 posts) and no slicing (only 
> as opSlice() I.e. as a whole). Best used for small things under 
> < 1000 bits (as even dup will be cheap enough).
>
> BitArray is class or struct that has reference semantics and 
> drops small array optimization in favor of having simple & fast 
> slicing Best used for big arrays with no less then 100-200 bits.

  Another thought coming to mind, is to have the BitArray with a 
few different modes it could operate in. One of the modes could 
be 'reference' which would make slices and them all work exactly 
as you would expect, while with referencing off it would act as a 
normal value type struct, since the mode/flags would modify how 
the postblit and assignment operators worked, along with the 
length. (Reference wouldn't use small array optimization).

  But having them statically separated by name/type seems much 
more likely to be safer in the long run with reliable results.


More information about the Digitalmars-d-learn mailing list