135 karma · joined January 16, 2025
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.
My question is: Does the author actually use Windows XP?
Having a well-defined memory model is important when running on infra with very different models, such as x86 and aarch64.
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.
To be clear, of course I'm also not immune to fucking up :-).
You can always mmap the file instead and let the OS page in and out parts of the file, however :-).
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