1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
class DataBlock_Offsets {
private:
uint32_t sma_offset;
uint32_t data_offset;
uint32_t string_offset = 0;
uint32_t dict_offset = 0;
}
template<size_t COLUMN_COUNT>
class DataBlock_Header {
public:
uint32_t tuple_count;
std::array<DataBlock_Offsets, COLUMN_COUNT> offsets;
uint64_t stop_offset;
std::array<EncodingType, COLUMN_COUNT> encoding_types;
}
template<size_t COLUMN_COUNT>
class DataBlock {
private:
DataBlock_Header<COLUMN_COUNT> header;
alignas(32) uint8_t* data;
///... many functions
}
|
I try to use sizeof(DataBlock) an sizeof(DataBlock_Header), they are much much larger than the sum of all the attributes.
When COLUMN_COUNT = 1, I got sizeof(DataBlock)=96 and sizeof(DataBlock_Header) = 40. So that consider this can not enlarged by the compuler padding, which normally less than 8 bytes.
So in this case, I checked the gdb to see, what is the problem. There are too many uninitiated 0 in the 40 bytes, indicated by sizeof(DataBlock_Header). The real part of attributes of DataBlock_Header are already initialized and take only a little part of space.
(gdb) x/40c datablock
0x55dfa95c6fa0: 0 '\000' 1 '\001' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000'
0x55dfa95c6fa8: 64 '@' 0 '\000' 0 '\000' 0 '\000' 96 '`' 1 '\001' 0 '\000' 0 '\000'
0x55dfa95c6fb0: 124 '|' 1 '\001' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000'
0x55dfa95c6fb8: 96 '`' 1 '\001' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000'
0x55dfa95c6fc0: 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000' 0 '\000'
Do you get any ideal, why is sizeof(DataBlock_Header) for example returns in this case 40? I can not get it.
And why is there a huge difference between the sizeof(DataBlock_Header) and sizeof(DataBlock)?