LWN.net Logo

Zeuthen: Writing a C library, part 1

Zeuthen: Writing a C library, part 1

Posted Jun 28, 2011 16:08 UTC (Tue) by HelloWorld (guest, #56129)
In reply to: Zeuthen: Writing a C library, part 1 by cmccabe
Parent article: Zeuthen: Writing a C library, part 1

> The whole point of classes like std::vector and std::string is that they do the memory allocations for you, and also handle cleanup. But that makes it a lot harder to do something sensible if the allocation fails.
No, it actually makes it easier. You don't have to check every operation that needs to allocate memory, and you don't have to manually clean up what has been allocated already when an allocation fails.

> If I can't create a std::string without getting an exception, that means I can't use std::string in a destructor.
If you need to allocate memory dynamically in a destructor, that's tough, but it doesn't make destructors less useful in the 95% of all cases where you don't.


(Log in to post comments)

Zeuthen: Writing a C library, part 1

Posted Jul 1, 2011 10:50 UTC (Fri) by jwakely (subscriber, #60262) [Link]

Exactly! (on both points)

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