135 karma · joined Jan 16, 2025 (1y ago) · 77 submissions
comment 1y ago · link · parent
Anyway, my conclusion is that in order to learn Rust you can't use any syntactic sugar the language provides, those are 'expert features'. There's no way I'd be able to figure out why this happens. Do rust-analyzer provide a way of desugaring these constructs?
comment 1y ago · link · parent
Cache locality matters, but so does having less allocator pressure. Use 32-bit unsigned ints as indices, and you get improvements on that as well.
>The original version of my b-tree works just like how you'd implement it in C. Each internal node / leaf is a raw allocations on the heap.
I'd always try to avoid that type of allocation pattern in C++, FWIW :-).
comment 1y ago · link · parent
comment 1y ago · link · parent
Good Rust code will also care about memory allocations to the same degree as the C code, the difference is that Rust will help you out in making sure your thinking is correct. My experience is that good systems programming has thinking about memory allocations not as an annoying side issue, but as a main concern.
comment 1y ago · link · parent
Having a well-defined memory model is important when running on infra with very different models, such as x86 and aarch64.
comment 1y ago · link · parent
This was instituted in Sweden in the year 1766. Source: https://sv.wikipedia.org/wiki/Offentlighetsprincipen
That's 10 years before the USA declared independence.
comment 1y ago · link · parent
To be clear, of course I'm also not immune to fucking up :-).
comment 1y ago · link · parent
Here's a much easier way to write the program:
1. Dump whole file into buffer as one string
2. Find newlines in buffer, replace with NULs. This also let's you find each line and save them in another buffer
3. Sort the buffer of all the lines you found
4. qsort the buffer
5. Print everything
6. Free both buffers
Or, as a C program: https://godbolt.org/z/38nq1MorM