Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
While a lot of the library looks useful, stuff like the above makes it feel like it's written by somebody who knows C, but doesn't feel fully comfortable writing it.
[1]: https://github.com/zpl-c/zpl/blob/master/code/header/essenti...
[2]: https://github.com/zpl-c/zpl/blob/27c80bd5807da5238777bfcba8...
It looks like ZPL has its own memcpy() implementation which is a work in progress. Assuming the author posted this as a Show HN kind of thread, here's some feedback I could offer based on my experience implementing that function.
It goes pretty quick on the machines I've used so far to have an indirect branch with overlapping moves. Here's what that looks like in "pure c" for gcc and clang. https://github.com/jart/cosmopolitan/blob/master/libc/str/me... memcpy is hard to implement in pure c99 because aliasing pointers to non-char types can trigger ubsan errors. With rep movsb it's a good idea to check cpuid for erms support. In that case it'll be fastest for bigger moves but is still slower for small moves. See the chart at https://justine.lol/cosmopolitan/index.html which compares various methods.
Regarding array.c I've lately found it personally easier to stop caring about capacity and just call realloc every time. I'm not sure if the standard specifies this, but I'm pretty sure every realloc implementation in practice, under the hood, should track the capacity and grow it at two power sizes. So even if you're just constantly appending by one char the cost short amortize itself out to be cheap in the long run.
Testing performance of memcpy should be more exhaustive than just running on single CPU: https://github.com/ClickHouse/ClickHouse/issues/18583#issuec...
> I collect different C libraries as a personal stash of toolkits
Might you have a write-up or link for these, and if so might you be willing to share it?
I have been using Sean Barrett's libraries [0], as well as his curated list of other people's single-header libraries [1], and, like you, I am always on the lookout for new things to add to the collection :)
[0] https://github.com/nothings/stb
[1] https://github.com/nothings/single_file_libs