User: Password:
Subscribe / Log in / New account

No thanks.

No thanks.

Posted Nov 10, 2012 23:22 UTC (Sat) by Cyberax (✭ supporter ✭, #52523)
In reply to: No thanks. by nix
Parent article: Haley: We're doing an ARM64 OpenJDK port!

Try it. I really mean it - try it. It would work just fine. Everything will be correctly destroyed.

>If, for whatever reason, you cannot use auto_ptr (which is, to be honest, simply pushing off the RAII memory-allocation overhead to something else that has already done all the work) how do you prevent the earlier-allocated ones from leaking?
By using auto_ptr or any other fitting smart pointer, there's literally no measurable overhead in using it. And there's no excuse in not doing it - and that was clear from the very start. That's actually a rationale for not including the "finally" keyword in C++ - because it might detract from using RAII.

Of course, if you really don't want to do it then you'll have to do the try..catch dance. Exactly like in C where ALMOST EVERY function might result in error and the most common pattern of error handling is "goto err_exit". That's actually why glibc handles OOM by calling abort() - it's simply too complicated to make everything in C error-safe.

PS: I had actually written a simple model verifier to verify my own collection library for upholding exception guarantees. That means that I've obviously read Sutter, Meyers, Stroustroup, Alexandrescu and quite a lot of other C++ writers.

(Log in to post comments)

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