Skip to content

BitArray could be using way less memory #397

@Bamboy

Description

@Bamboy

I was very surprised to see that BitArray uses bool[] as an underlying type. If you didn't know, the bool type in C# actually allocates an entire byte of memory because that is the minimum addressable size used by the CLR. You waste 7 bits for every bool. See https://stackoverflow.com/questions/2308034/primitive-boolean-size-in-c-sharp/2308052

I see @LorenzoLotti was the original contributor so I'm tagging them.

A maximum performance gain would be to use byte[], int[], or long[] as the underlying data type and then use bitwise operations to get the bit value you actually want.

This improvement seems minor compared to the effort to implement, but could maximize memory usage for very large data sets.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions