Buffet – An All-inclusive Buffer for C
A very well thought out set of functionality. It covers a lot of ground. In particular:• The reference counting of the bft_view can simplify reasoning in a C program.• The cheap bft_view 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.• 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.• 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'.• 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.