Buffet – An All-inclusive Buffer for C
A very well thought out set of functionality. It covers a lot of ground. In particular:<p>• The reference counting of the bft_view can simplify reasoning in a C program.<p>• The cheap <i>bft_view</i> may keep programmers from copying as much data. It's easy to fall into a "copy everything" mode in C since that's what the runtime library provides and consumes. Working with slices reduces your cache pressure and is just generally faster.<p>• Allocating only blocks sized by a power of two is potentially memory wasting. The exponent for the size has a range of 0...255, but it only needs to get to 2^32 since that's the largest allowed length. I suspect there is some clever base between 1 and 2 which is trivial to compute the exponent and inverse in integer arithmetic. (Or similarly shaped function, it doesn't have to be an exponential, just something that grows about like one.) This would provide better granularity.<p>• Alternatively, some bits could be harvested from 'cap' to say how the memory should be freed, usually it is  'free', but one could imaging adding a few lines to support 'mmap', then the release becomes 'munmap'.<p>• Now that we have imagined up mmap capability, this looks like a very nice way to handle many kinds of data files which are not character oriented streams processed sequentially.