3 ms·
Shameless plug: This generally discusses the lack of RAII in C (towards the end), and what to do about it: https://floooh.github.io/2019/09/27/modern-c-for-cp
by flohofwoe 6y ago
Shameless plug:
This generally discusses the lack of RAII in C (towards the end), and what to do about it:
https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.html https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.h...
...and this presents a (reasonably runtime-safe) general memory management strategy using tagged-index-handles instead of pointers:
https://floooh.github.io/2018/06/17/handles-vs-pointers.html https://floooh.github.io/2018/06/17/handles-vs-pointers.html
The gist is basically:
- don't allocate small chunks of memory all over the code base, instead move memory management into few centralized systems, and let those systems own all memory they allocate
- don't use pointers as public "object references", instead use "tagged index handles"
- don't use "owning pointers" at all, use pointers only as short-lived "immutable borrow references"
- ngcc_hk 6y agoAnother global (imperative style) vs object (code and data by object) vs functional ...
- heinrichhartman 6y agoThanks for this!