I'm trying the construct a struct in C++ as below:
struct kmer_value {
uint32_t count : 32;
uint32_t path_length : 32;
uint8_t acgt_prev : 4;
uint8_t acgt_next : 4;
}
The struct currently takes the memory of 12 bytes, but I want to reduce the size to 9 bytes. Is there any way to realize it?
Thank you.
There's no portable solution. For GCC that would be
struct __attribute__((packed)) kmer_value {
uint32_t count : 32;
uint32_t path_length : 32;
uint8_t acgt_prev : 4;
uint8_t acgt_next : 4;
};
In MSVC #pragma pack
can achieve the same effect.
Consult your compiler's documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With