| 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. |
> A very well thought out set of functionality
Thanks! It's only an experiment at this stage but I was pleasantly surprised it worked in such a small size.
> slices (...) generally faster
It works wonders. The upcoming bft_split function is gonna be dead fast.
I optimize things by adopting the laziest possible personna : do I really need to copy this ? No. What if the user wants to append stuff to a split part ? We'll see then.
> Allocating only blocks sized by a power of two is potentially memory wasting
It just follows the classical doubling of requested size. In high exponents though I admit it'll be wasteful.
> some clever base between 1 and 2
I wouldn't have thought of it, nor known how to. Would it be somehow costly ? Shifting is basically free.
> support 'mmap'
Interesting. But shouldn't we keep the lib surface minimal and just leave this to the user ? She maps then takes a view on it ?