Stupid Smart Pointers in C
blog.kevinalbs.com
Stupid Smart Pointers in C
1–10 of 174 posts
Re: Stupid Smart Pointers in C
#2Re: Stupid Smart Pointers in C
#3Re: Stupid Smart Pointers in C
#4I wonder how that affects compiler optimization
Re: Stupid Smart Pointers in C
#5C programmers are better off with either of these two techniques:
* Use __attribute__((cleanup)). It's available in GCC and Clang, and we hope will be added to the C spec one day. This is widely used by open source software, eg. in systemd.
* Use a pool allocator like Samba's talloc (https://talloc.samba.org/talloc/doc/html/libtalloc__tutorial...) or Apache's APR.
(I didn't include using reference counting, since although that is also widely used, I've seen it cause so many bugs, plus it interacts badly with how modern CPUs work.)
Re: Stupid Smart Pointers in C
#6Re: Stupid Smart Pointers in C
#7[0] https://thephd.dev/c2y-the-defer-technical-specification-its...
Re: Stupid Smart Pointers in C
#8Re: Stupid Smart Pointers in C
#9Really, don't do this, it's a portability and safety nightmare (aside from C not being memory safe already). C programmers are better off with either of these two techniques: * Use __attribute__((cleanup)). It's available in GCC and Clang, and we hope will be added to the C spec one day. This is widely used by open source software, eg. in systemd. * Use a pool allocator like Samba's talloc ( https://talloc.samba.org/…
Interesting. I'm not very proficient in C, this looks like some sort of finalizers for local variables?