Comment 6 for bug 1440186

Revision history for this message
Ambroz Bizjak (ambroz-bizjak) wrote :

Regarding the new char alignment, it seems like it is guaranteed: http://stackoverflow.com/a/10589019 . There is a reference to the standard text and I was able to find this in C++98 and C++11.

I agree with Andrew about making a union to save a few bytes per allocation. But, we should be careful not to allocate too little (when _readNotifytCacheSize is lesser than the size of pNext). I suggest this:

struct cacheElem_t {
    size_t size;
    union {
        struct cacheElem_t * pNext;
        char buf[1];
    } u;
};

Allocate: max(sizeof(cacheElem_t), offsetof(cacheElem_t, u) + _readNotifyCacheSize)