-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Add bit_set container (and considering using bit_set in enum containers) #156
Comments
The reason Overall it would be better to use bits instead of bytes if it meets all the "fixed_container" requirements. Performance seems to be an on-par for access, and construction favors the smaller one. I wouldn't be surprised if some things are slower given the access patterns, but the footprint is for sure much smaller (at least for Are there any cons in always using bit_set in EnumSet? |
I figure that's why I start using xstd::bit_set, but switched later to
Yea I forked it years ago and update it from time to time, but some C++23 features (or other things) broke my build, so I rolled back. (older versions works fine for me)
Right now it works for me, but the most operations I do are I was experimenting with sizes and alignment to keep my structs as small as possible and feel like For example... struct MyGameComponent {
EnumSet<Status> statuses; // Size: 48, Align: 8 (38 enums)
EnumSet<CanDoAction> can_do_actions; // Size: 32, Align: 8 (18 enums)
}
struct BattleStats {
EnumMap<Attributes, int32_t> base_stats; // Size: 48 (7 enums)
}; With bit_set struct MyGameComponent {
EnumSet<Status> statuses; // Size: 16, Align: 8 (38 enums)
EnumSet<CanDoAction> can_do_actions; // Size: 16, Align: 8 (18 enums)
}
struct BattleStats {
EnumMap<Attributes, int32_t> base_stats; // Size: 40 (7 enums)
}; (size is also always the same, which can be nice.) |
In my fork, I used the MACRO |
IMHO adding a ( |
(sorry for the delay) |
Hello,
I was experimenting with
bit_set
in my own fork, replaced the internalstd::array<bool>
members withbit_set
.(Right know I'm using
bit_set
, I needed a more "modern"bit_set
with fixed length andconstexpr
)1. Using
bit_set
asarray_set_
in myEnumSet
:2. Using
bit_set
asarray_set_
in myEnumMap
My main goal was to reduce the memory-foot-print, but the best thing I can do was
sizeof
and benchmark for speed :)EnumMap (random access)
Without
USE_BIT_SET_IN_ENUM_MAP
(std::array<bool>
)With
USE_BIT_SET_IN_ENUM_MAP
(bit_set
)EnumSet (random access)
Without
USE_BIT_SET_FOR_ENUM_SET
(std::array<bool>
)With
USE_BIT_SET_FOR_ENUM_SET
(bit_set
)EnumMap (construct)
Without
USE_BIT_SET_IN_ENUM_MAP
(std::array<bool>
)With
USE_BIT_SET_IN_ENUM_MAP
(bit_set
)I guess the more
key
s an Enum has, the larger thestd::array
gets ... withbit_set
it's more limited.The text was updated successfully, but these errors were encountered: