libpmemobj-cpp
libpmemobj-cpp copied to clipboard
concurrent_skip_list: how to handle zero-sized variables (compare/allocator)?
I propose to add explicit member in structures like comparator and alloctor (1 byte). Additionally all code which uses comparator and allocator should use explicit padding like this:
struct {
allocator alloc;
char padding[3];
int x;
}
The reason for this is that standard does not guarantee that empty struct is 1 byte. Additionally changing the type of surrounding members could change the implicit padding (we can think about solving this generally).
Moreover, we should implement pmem::obj::comparator and use it instead of std::less.
I think we also should align concurrent_hash_map design in the same way.
regarding your example, you changing the layout of the structure which contains allocator but not allocator itself. How padding inside allocator would help?
You're right, I've changed the description. I was thinking about aligning the allocator/comparator to 8 bytes (in that case, there would be no implicit padding between allocator and following datatype if it requires alignement <= 8). But probably a better approach is to add explicit padding in the hash_map/map itself (and just test it using layout tests).