itinero / reminiscence

A library for cross-platform memory mapping.
MIT License
9 stars 6 forks source link

Support for bool arrays. #10

Open xivk opened 7 years ago

xivk commented 7 years ago

Implement support for boolean arrays where one bit represents on bool.

We need to make breaking changes because this would make the elementsize < 1 byte.

juliusfriedman commented 4 years ago

Was thinking abou this, You could also make it such that a bool[] has a default elementSize of 1 and the remaining bits are unused to preserve the elementSize == 1, the 7 bits would be wasted in cases where there was only 1 bit being used but it would allow for using them if required e.g. via Resize.

Each resize would add 8 bits and you could use only the bits out of the byte which you require.

If you can give me a little guidance I will implement this when I have time and submit a PR

xivk commented 4 years ago

Not sure I follow completely here... So you are saying instead of supporting Array support Array<bool[]> and assume each element to have 8 elements?

juliusfriedman commented 4 years ago

Yes, essentially.

I felt like it would be easier than making changes to the elementSize which is always at-least 1 byte and would otherwise require reading bits which would likely need an even bigger change.

This way you can assume the bool[] to support 8 bits with element size = 1, 16 with size = 2 etc.

This is more or less just specializing the use of bool to read in bits from a byte where as your suggested change would be to implement arbitrary bit reading would would be a bigger change.