LWN.net Logo

Object-oriented design patterns in the kernel, part 1

Object-oriented design patterns in the kernel, part 1

Posted Jun 3, 2011 9:46 UTC (Fri) by cortana (subscriber, #24596)
In reply to: Object-oriented design patterns in the kernel, part 1 by Cyberax
Parent article: Object-oriented design patterns in the kernel, part 1

FYI, you can still use shared_ptr with FILE* (and probably any other C API that follows the same pattern.

shared_ptr<FILE> f (fopen ("whatever", "r"), fclose);

Now, fclose will be called whenever the last copy of that shared_ptr is destructed. No more single exit points, goto tricks, or leaning towers of if statements!


(Log in to post comments)

Object-oriented design patterns in the kernel, part 1

Posted Jun 3, 2011 12:30 UTC (Fri) by cmccabe (subscriber, #60281) [Link]

That's pretty good, and it relies on things that are actually in the standard library. Thanks.

Object-oriented design patterns in the kernel, part 1

Posted Jun 3, 2011 14:19 UTC (Fri) by cortana (subscriber, #24596) [Link]

This and std::vector are the best things in C++! :)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds