libpmemobj-cpp icon indicating copy to clipboard operation
libpmemobj-cpp copied to clipboard

concurrent_skip_list: how to handle zero-sized variables (compare/allocator)?

Open igchor opened this issue 4 years ago • 3 comments

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.

igchor avatar May 19 '20 11:05 igchor

I think we also should align concurrent_hash_map design in the same way.

vinser52 avatar May 21 '20 10:05 vinser52

regarding your example, you changing the layout of the structure which contains allocator but not allocator itself. How padding inside allocator would help?

vinser52 avatar May 21 '20 10:05 vinser52

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).

igchor avatar May 21 '20 11:05 igchor