BitArray - preview of what's to come?

Era Scarecrow rtcvb32 at yahoo.com
Wed May 30 12:25:40 PDT 2012


On Wednesday, 30 May 2012 at 11:19:43 UTC, Dmitry Olshansky wrote:
> It all went nice and well...
> Ouch why 36 bytes?

  Well for the whole normal size it was 32bytes, or 24 if I drop 
the ulong 'reserved' which does a minor optimization so it can 
expand rather than duping every time it expands (but slices know 
not to expand and dup). Otherwise...

  auto x = BitArray(1000);
  auto y = x[256 .. 700];

  x ~= true; //expands without resizing (Leftover space)
  y ~= true; //overwrite bit 701 in x? Dups instead

  There's also much faster prepending of bits (Thanks to slice 
support). So...

  x = true ~ x; //dups & reallocates once, but not O(n) slow
  x = false ~ x; //uses reserved space at beginning used, so O(1)

Let's see, 32bit systems if we have 24 bytes, and 4 bytes for the 
overhead, 20*8, 160 bits would be available, or 32bytes with 28 
bytes extra at 228 bits

On 64bit systems, you'll have 32bytes, 24 avaliable, so 192 bits. 
or 40bytes with 32, giving 256 bits. I will the current to at 
least match the regular/normal one equally so some space isn't 
lost, but it won't be by much.

  If you drop it down to a simple pointer (like the original), 
than slices and extra features and optimizations go away.


More information about the Digitalmars-d-learn mailing list