News for hackers. Stuff that matters.
Re:Building a Cloud Database from Scratch: Why We Moved from... by lelanthran on Saturday May 28, 2022 @02:35AM (#31538091)
> 1. You'll leak memory.

>

> This is super easy to solve in literally 300 lines of code or less. Just have a vector of your memory allocations in debug mode. Then call a custom allocator and free function that adds an allocation and removes an allocation from this list. At the end of the program, print out any allocations that are in the list that never got freed. You can use macros to print the exact file and line number that allocated the memory and then fix it very quickly.

I've got similar macros for C, but it is still less work to simply use valgrind.

Re:Building a Cloud Database from Scratch: Why We Moved from... by _gabe_ on Saturday May 28, 2022 @09:13AM (#31540084)
Nice :)

Valgrind is easier, but for real-time applications I've found that it takes a huge performance hit for some reason, at least the last time I used it.

Re:Building a Cloud Database from Scratch: Why We Moved from... by lelanthran on Saturday May 28, 2022 @11:45AM (#31541225)
> Valgrind is easier, but for real-time applications I've found that it takes a huge performance hit for some reason, at least the last time I used it.

It does, because it runs the app in an emulator.

What I did in the past (around 2005) was to write replacement malloc/calloc/realloc/free calls, put them into a libmymalloc.so, and then set LD_PRELOAD to point to libmymalloc.so.

This way I could switch between my malloc routines and the system malloc routines without recompiling the program.

Re:Building a Cloud Database from Scratch: Why We Moved from... by jbboehr on Saturday May 28, 2022 @06:33PM (#31544454)
talloc[0] is a pretty cool allocator that also has the ability to do this sort of thing.

[0]: https://talloc.samba.org/talloc/doc/html/index.html