|
|
|
|
|
by kstenerud
2366 days ago
|
|
C was my first love, and I still find myself using it often, especially in library code when I want versatility. I've gotten into the habit of pushing memory allocations as far back into the user program as possible (where the user asks for the size of the internal struct, allocates and casts, and deals with ownership himself) to allow more flexibility to the users of my libraries, and also to remove entire classes of memory issues from the libraries themselves: https://github.com/kstenerud/c-cbe/blob/master/tests/src/rea... As a bonus, it avoids the headaches of mixing multiple allocators (malloc, new, [NSObject alloc], JNI, etc) when used in cross-language codebases. It does, unfortunately, complicate the API a little bit, but I find the tradeoff to be worth it in terms of safety. |
|