Saturday, June 12, 2010

RAII vs finally

Since I'm pretty new to C++, I wasn't too deeply familiar with RAII; like most Schemers I just thought of it as "C++'s version of dynamic-wind."

This week I learned an important distinction between C++ destructors and Java's finally. The latter, of course, unilaterally executes when the body terminates, regardless of how or when it terminates. The thing that gives destructors more expressiveness for dealing with cleanup is that they only execute for the objects that have been initialized. This means that if control exits a block after only half of the stack-local objects have been constructed, only those half of the objects have their destructors invoked. With finally, all that bookkeeping is the responsibility of the programmer.

(That said, I still see RAII used all over the place to construct awkward, special-purpose classes whose sole purpose is to run some cleanup code. In these cases, having to create a named object and a named class to go along with it is pretty perverse.)

81 comments:

Jeremy Fincher said...

The other major benefit of RAII over a "finally" block is that the former cannot be forgotten: programmers can easily write poor code by forgetting a finally block, but they cannot make the same mistake if the functions they call return only resources managed by classes with appropriate destructors.

Paul Steckler said...

Lately, I've thought of Dorothy's departure from Oz as a non-local exit, like an exception throw or continuation invocation, combined with resource/object cleanup.

This particular metaphor is aided by the fact that Kansas begins with a `k'. And you can think of the words "I'm melting!" as the sound of destructors in action.

tonyg said...

I like Scheme's call-with-input-file (and friends) and Python's "with" statement as approaches to this problem. Both are used to bound regions in which a resource is available for use, with automatic cleanup as appropriate for the type of control transfer used to exit the block. I guess they share some of the problems of RAII, actually, with respect to the need for out-of-line pieces of code for resource management. Does "nested finally" help avoid the manual bookkeeping you mention? Have you been considering any alternatives that combine the virtues of both RAII and finally?

Jeff said...

(That said, I still see RAII used all over the place to construct awkward, special-purpose classes whose sole purpose is to run some cleanup code. In these cases, having to create a named object and a named class to go along with it is pretty perverse.)

You can get rid of some of this boilerplate with smart pointer classes that take a function to call when the pointer goes out of scope. Something like boost::shared_ptr allows you to pass a function in to be called when it goes out of scope.

Sage said...

steck - that is inspired! Hope you don't mind but i'm having that little visual image to help my memory along as well!

wleslie said...

We recently had a very interesting discussion on this subject on cap-talk that you might enjoy: http://www.eros-os.org/pipermail/cap-talk/2011-March/thread.html#14632

3D4PC-Ryan-Newby-3D- said...

Very interesting but over my head, Hardware Man.

Rithi Rawat said...

Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
Check out : machine learning training in chennai
machine learning projects in chennai
machine learning tution in chennai
artificial intelligence and machine learning course in chennai

OGEN Infosystem (P) Limited said...

Great and valuable information put in this blog, thank you so much for sharing this information with us. Visit OGEN Infosystem for responsive web design and SEO Service.
SEO Service in Delhi

Anonymous said...

QuickBooks File Doctor is the program that helps the user to troubleshoot any type of QuickBooks error. These errors may have been hindering the processes.

Amara James said...

Are you all aware about the information on many movies downloading websites like moviesbaba bollywood?
If not then also no need to worry as this article will surely going to help you to get all information about the given topic and about 123movierulz.
Along with it jalsamoviez.pw also shows the best and latest movies online from where you can even download them.
Thanks.

Channel Activation said...

I take pleasure in introducing myself as an expert who could help you in the selection and activation of the best channels available. There are so many channels available today on television. There is every chance of you missing the best channel because of not being aware of it.

visit my site : espn.com/activate

dhanuvarma said...
This comment has been removed by the author.
Roku Hdcp said...

The special features of PBS Channel include the PBS Passport that it provides. PBS Passport benefits from membership in PBS stations that provide access to a professional on-demand on-line public television archive to qualifying subscribers.if you need more information about pbs channel visit pbs.org/activate

Roku Hdcp said...
This comment has been removed by the author.
alexcosta said...

thanks for information.Tubi is a video streaming service, not unlike Netflix, Hulu, Amazon Prime Video and others, with an extensive library of TV shows and movies that you can watch free of charge from your phone, smart TV or streaming device. If you need any assistance tubi.tv/activate on roku please contact our technical support +1-844-525-1240 to get more information.

elenasmith said...

Hello, Thanks for sharing the amazing blog. It's very interesting.
here are the office setup and installation at https://officesetup.support/.You need to have an Active Office Subscription to download Office on your PC to enjoy all the features. The office is one of the best software that will give you support for all your pen devices as well as flexibility. So, get your office setup www.office.com/setup

James Whatt said...

Choose Pandora's music that you love. Create custom stations from your favorite songs and artists or upgrade to Pandora Premium's songs, albums, and playlists on-demand. Get the best from the best and all you need to do is activate Pandora on Roku. Navigate to the channel store from the home screen and search for Pandora. Find a code on the screen after which you will have to navigate to the Pandora.com/activate roku enter code. Enter the code and click on submit to successfully add the channel. Now, you are free to listen to any of your favorite songs on Pandora. For any additional queries, contact the active customer care team @ +1-888-298-2680, working 24X7

pollard Holmes said...

Got confused in proceeding the activation setup for your Roku account? This instruction might help you to proceed with the activation with the clear steps. Complete all the initial setup like setting the preferred location, language, and wireless setup. Once done visit the Roku site and create the account by entering the required credentials. You will receive the activation code on the Roku screen. Visit the Roku.com/link and enter the Roku account activation code displayed on the Roku screen. For further details get in touch with our customer support team@ +1-844-489-7600

greyhankin said...

It’s not a tough task to activate Roku. Connecting the hardware is the first step. Visit the signup URL for account creation. Collect the code. Open the new browser to paste the URL, Roku.com/linkand wait for the prompt to enter the activation code. For assistance and to know more about device setup and troubleshooting, reach out to our customer support at the earliest.

Lanedavis said...

Can’t talk to the Cash App representative on the Cash App Phone Number?

We at Cash App believe in giving our customers unhindered support whenever they face an issue. That’s why, we provide support through email, chat and phone number. However, the phone number gives an automated response as we don’t have any physical representatives. Therefore, if you face any issue call Cash App Phone Number to get the problem fixed.

Unknown said...

Do this hack to drop 2lb of fat in 8 hours

Well over 160k women and men are trying a simple and SECRET "liquids hack" to burn 1-2 lbs each and every night in their sleep.

It is very easy and works with everybody.

This is how you can do it yourself:

1) Go grab a glass and fill it up with water half full

2) Proceed to do this proven hack

and you'll be 1-2 lbs thinner the very next day!

John David said...

Check out the recent articles on our webpage to get an idea of Roku.com/link activation, tips to resolve Roku.com link errors and it’s quite informative. Start writing and you will never end up feeling bored
If you are new to Roku, refer the instructions and setup process becomes much easier

sammer mark said...

Wow!!! Awesome post I really love to read your post. If your are looking or facing from printer related issues like www hp com setup, etc. Our team is available for resolve your printer related any issues in the simple way by our expert technician.

sammer mark said...

Awesome post. I simply stumbled upon your weblog and wanted to mention that I have really loved surfing around your blog posts. If you are facing problem regarding HP Printer in Error State. Call our Toll-Free number or visit our website for more details or any information. We are available 24 x 7.

The Qb Payroll said...

Avail best customer experience with QuickBooks Customer Service Phone Number 1-833-780-0086. Our QuickBooks experts offer quality & genuine assistance. FOr More: https://g.page/qb-support-oregon

Aiden Jangra said...

Its really interesting and amazing blog, Its very informative and helpful for me. I appreciated your hard work and skills. HP printer setup Thanks for sharing!

Roku Com Link said...

Thanks for sharing this information with us. I am just surfing on internet and suddenly found this blog. Very Nice blog. Please have a look on my blog which is based on Roku com link settings.

sammer mark said...

Your posts are really different from others. It contains good blogs Thank you for sharing really informative blogs. If your How to Fix Error During HP Wireless Printer Setup or any other HP printer related issues Call Our Toll-Free number.

Technical Support and Services By Experts said...

Thanks for sharing such a good content with your blogs. I really enjoying your blog while reading. if you need any kind of information CONNECT Brother Printer Number
brother printer customer support
brotehr printer drivers

Anirban Ghosh said...

I would like to thank you for getting my neurons conspicuous with this brilliant article that you have written which contains every potential points which needs to considered on the given topic. Thanks for chipping in such a brilliant writing!
SAP training in Kolkata
SAP training Kolkata
Best SAP training in Kolkata
SAP course in Kolkata

carolineangela said...

Hp envy printer 5055 support | It is my utmost desire to explore all the digital products as a whole. Passion doesn't fade away and I've always liked to explore more . Refer my blogs and articles regarding the issues you face with the HP printer | +1-844-485-5080 | Hp envy 5055 keeps going offline

Channel Activation said...

Hey there, I'm Ara I work as a Freelancer living in Washington. I read Books a lot that's my hobby too. You can visit my favorite website Channels TV Live | univision.com/activate

Arga Detectives said...

Detectives privados Madrid Asociados es un despacho de investigación privada en Madrid con gran experiencia. Contacta con los mejores detectives privados en Madrid para todo tipo de investigaciones privadas.

detectives privados madrid
agencia detectives Madrid

Thank you..

Ronaldo drogba said...

activate roku com link
With great passion for writing, I started writing short stories and essay. Now I write about internet and technology related blogs. Do check out my write-ups here | roku.com/link

Jennifer Lauren said...

Here, the user tracks a Facebook report a problem if it is active for a time. Usually, the social network doesn’t mention this practice in its data policy. If the account is disabled, then it meant to hide their accounts. If you still any queries about this, then feel free to contact the support team for help.

Alejandraleo said...

On the off chance that there's a mistake in the interface that prompts disappointment of tasks and you're figuring; how can I speak to a Yahoo representative ? At that point you can utilize the assistance that is offered by client care. All you gotta do is to dial the assistance number that is given on the web

Alejandraleo said...

Cash app is a shared payment banking application and it is possessed by Sqaure Inc. which is a leader in the financial innovation industries in the USA. The Cash app is just a part of it., that offers you to make a transaction. You can also utilize this application for your business. If any issues, go to realize how do I talk to a Cash app representative

Srigokul said...

Thanks for Sharing this useful information...
Great job, keep doing like this...

Data science training in chennai
Data science course in chennai

Unknown said...

Useful post Thanks for sharing it that’s truly valuable knowledge about similar topic. Amazing. Have a more successful day. Amazing write-up always finds something interesting.
Personality Development Classes

Ronaldo drogba said...

Roku setup | Roku is the kind of network that will always entertain the users. for more about Roku visit the below link Roku setup

99 Digital Academy said...

I feel good to read you article. Really it is very informational. Here I have suggestion for your that the Best Digital Marketing Course offered by 99 Digital Academy. The course is designed for students, professionals and for business owners. This course is in trend. Click on link to see more.

Epson Printer said...

I referred epson.com and I was so glad to get guidelines for my Epson Workforce WF 7720 Printer Setup Solution. This was extremely helpful for me to use while I Setup my Epson Printer.

Anonymous said...

Nice blog post,
Digital Marketing Course with Internship Keeping the demand for digital marketing and the job openings that are expected to open in the coming days in mind, we make sure that our Digital Marketing course comes with an internship that focuses on making you work on real-time live projects.

Priya Rathod said...

This was a wonderful post being shared. The entire content in this blog is extremely helpful for me and gave me a clear idea on the concepts.
Data Science Training in Hyderabad
Data Science Course in Hyderabad

Priya Rathod said...

The best thing is that your blog really informative thanks for your great information!
DevOps Training in Hyderabad
DevOps Course in Hyderabad

pepsmattresszone said...

Peps Mattress in Chennai
Peps Mattress Chennai

cloneapps said...

Goappx
Delivery app clone
Uber for freight clone
Uber clone
Zillow and trulia clone
Ecommerce Clone
Justeat clone
Tiktok clone
Uber for x clone
Uber for courier
Uber for tow trucks
Periscope live clone

Priya Rathod said...

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
Data Science Training in Hyderabad
Data Science Course in Hyderabad

Bestforlearners said...

Best Ethical Hacking training institute in Bangalore
https://www.bestforlearners.com/course/bangalore/ethical-hacking-course-training-institutes-in-bangalore

James Whatt said...

Are you a new Roku user and unaware of Roku setup, activation, and account creation by visiting the Roku.com/account? It is simple to set up the Roku device. Follow the steps given: First, you can connect the Roku device and your TV using HDMI or composite cable. Then, power on the device and TV. Now, follow the on-screen guidance to connect the device to your network and continue following the prompts. Finally, an activation code displays. Go to the Roku.com/link account and click the activate a device tab and Key in the activation code. Click the submit button, and on the next screen, you will be requested to create a Roku account. Complete all the procedures instructed. Now, you are ready to stream the video content on Roku. For further clarification about the Roku.com/link account, please contact our executives.

Epsonprintersupport said...

I never used to comment on blogs. After reading your post titled Roku activation using Roku.com/link enter code, I’m impressed and excited to mark the best review rating.
The activation guidelines are clear and easy to understand. Awaiting more interesting blogs from now on.

John Williams said...

Here we suggest the troubleshooting tips to get rid of go.roku.com/lowpower issue.
At first, understand what causes the error
Check the power cables connected to the device
If the Power cable used is faulty, replace it with a new one
Restart your device and check if go.roku.com/low power issues resolve
Do not place any electrical interference between your Roku device, TV, and Router
Never allow your device to heat up. Turn off your device and ON it after a while
Please contact our customer support for troubleshooting assistance

Roku Link setup said...

Are you guys unaware of the Roku Activation Code? I’m glad to share with you the most recent blog about Roku Streaming devices. The blog explains the setup and how to get Roku activation code for activation steps. The setup procedure is given for all the Roku models. In addition, they also provide the troubleshooting step for all Roku error codes. I suggest you read the blog for more information about the Roku activation code. You can also share the article with your family and friends who’s unaware of the Roku device.

Peter Hector said...

Here is the troubleshooting guide to fix Xfinity Stream Roku not working

At first, understand the error cause
Check the compatibility of xfinity stream roku app to use with your device
Uninstall the app and install it again
Always connect your device to a good speed network before activating Xfinity service
Upgrade your device software with the latest version
Learn Xfinity activation steps clearly before execution
Please contact our customer support for troubleshooting assistance

richardburton04 said...

Let us help to fix Roku Error Code 009 by suggesting the blog post titled, Troubleshooting guide to fix Roku Error Code 009 . Please read the post to understand how to begin the troubleshooting. It’s hard to operate Roku without resolving the error
Also share the post with Roku users

Unknown said...

The future of digital marketing is promising and full of possibilities.
As a result, skilled digital marketers who can keep up with the rising demand are in high order.

In the Emblix Academy Digital marketing institute in KPHB, you will learn about all the major and minor modules of digital marketing, from Search engine marketing to Social Media Marketing and almost all Tools used for Digital Marketing.

One stop place for all Digital Marketing courses! Emblix Academy is a Team of dedicated Professionals with 12years of experience in various Digital Platforms. We assure to provide the best Digital Marketing courses to enhance your Career.


https://emblixacademy.com/

Robert Smith said...

To learn how to setup HP Printer using 123hpcom/setup?, here we explain the Printer setup steps in detail. The steps include connecting the hardware, activating the  network, selecting the language, display, and network settings. After selecting the required settings, install the Printer driver. Then add Windows,  Mac computer to start operating the printer. If you need any help to setup HP printer, fix setup errors that pop up on your device display screen,  please contact our Printer customer support team right away. 

John David said...

Our Digital Product Engineering Services engage with customers with an innovative feedback system

“Indium Software has produced a revamped solution that improves the efficiency of the client’s billing. The new product boasts automated tracking, reporting, and data-saving functionalities. The team has been communicative and flexible vis-à-vis the client’s schedule and changing requirements.” Product engineering services
For more details reach us @ 18882075969

Robert Smith said...

Let us help you to download HP printer driver to proceed with 123hpcom/setup. At first, understand the driver download process. Then choose a compatible mobile device or tablet. Access the portal 123hpcom to find the software search tab. Enter the Printer Name, Version to find the software search results. Move the setup file to the required folder. Click on the setup file and go forward to execute the software installation. If you find it hard to find the matching software to use with your Printer, get help from our printer customer support team.
https://www.123hp-com.com/

Robert Smith said...

Let us help you to execute 123.hp.com/dj3630 setup. The process is easy, if you understand 123.hp.com/dj3630 setup steps At first, fix the hardware and then proceed to establish the connection. If the connection is active, go to the devicecontrol panel; select the option, wireless setup wizard. After selecting the settings, the list of available network willappear. Provide the credentials to activate the connection.Thesoftware update is the next step. You can visit the software download page, and then provide the required data. Nowgoback to 123.hp.com/dj3630 setup steps Never delay contacting our experts if you require any help to begin the device setup.

HP Printer Setup said...

Downloading and installing HP printer driver using the page, 123.hp.com or123.hp.com/setup. You can access the driver download portal. Then go to driver search tab and provide the Printer name, Version. Get the driver search results. Select the driver and tap on the icon, download. The driver download process will start now. Tap on the driver setup file and run the onscreen commands that appear to complete HP printer driver installation. Please talk to our network support team if you require driver download assistance

Fubotv Activate said...

Since fuboTV started out as a sports-only service, they do provide a extensive range of sports activities and sports-related media. It has the primary leagues, like the NFL, NBA, MLB and NHL, as properly as NASCAR, MLS, golf, tennis, boxing, MMA, university sports, and more. The provider has insurance for the world’s most necessary wearing events, like the Superbowl, the NBA Finals, the MLB World Series, the Stanley Cup Playoffs, and the Olympics. fubo.tv/connect code

Robert Smith said...

HP LaserJet pro m15w driver installation using the driver download portal.

-To start the driver download, choose a compatible device
-Then connect your device to a secure network
-Go to the device control panel to find the appropriate network settings
-Now learn how to download HP Laserjet pro m15w driver
-From your device, access the driver download page
-Go to the driver search tab
-Type the Printer name, Version
-Get the driver search results on your device display screen
-Choose HP Laserjet pro m15w driver from the search results
-Click on the icon, download
-The software download process will start now
-You can move the driver setup file to the required folder
-Click on the setup file
-Finally, run the onscreen commands that appear on your device display screen
-After completing the driver installation, proceed with the remaining Printer setup steps such as adding Windows or Mac computer
-If you prefer using the software CD, insert the CD to the Computer
-Access the software CD
-Then tap on the setup file to begin the installation process
-You are requested to wait until the driver download process complete
-Check the compatibility of HP Laserjet pro m15w driver before installation
-Else you may get stuck with driver issues
-If error codes occur, you can uninstall the driver and install again
-Device reset can also help to fix common software issues that occur
-Meanwhile, check for software updates regularly
-Note that you can also use tools such as HP easy start to find and update the software automatically.

Unknown said...

Here at this site really the fastidious material collection so that everybody can enjoy a lot. business analytics course in kanpur

sultangazi Nakliyat said...

Tüm hemşerilerimizin Regaip kandilini buradan yorum backlink aracılığı ile kutlarım. Sultangazi Evden Eve Nakliyat

Data Science said...

Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting.
A debt of gratitude is in order for sharing.business analytics course in kolhapur

Unknown said...

I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site. data science training in surat

traininginstitute said...

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one.
data scientist training in malaysia

Unknown said...

Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written. data science training in surat

digital marketing malaysia said...

I was basically inspecting through the web filtering for certain data and ran over your blog. I am flabbergasted by the data that you have on this blog. It shows how well you welcome this subject. Bookmarked this page, will return for extra.

Ramesh Sampangi said...

Really an awesome blog and informative content. Keep sharing more content with us. Thanks for sharing with us.
Data Science Training in Hyderabad

Unknown said...

I'm hoping you keep writing like this. I love how careful and in depth you go on this topic. Keep up the great work business analytics course in mysore

360DigiTMG said...

Always so interesting to visit your site.What a great info, thank you for sharing. this will help me so much in my learning
data science coaching in hyderabad

PMP Training in Malaysia said...

360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.

Unknown said...

This post is very simple to read and appreciate without leaving any details out. Great work! data science training in surat

Unknown said...

I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more. data science course in kanpur

Al Eizba said...

Thanks for posting a valuable and informative blog. Further, If you are looking Dubai South Villas visit our website.

data science course said...

"I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. data science course kanpur"

GoLogica said...

"I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new article.

Here is sharing some data analytics ForgeRock Interview Questions and Answers overview concepts may be its helpful to you.

ForgeRock Interview Questions and Answers

sajinfoworld said...

The content that I normally go through in the recent times is nothing like what you have on paper. Thank you for writing this!
Computer services center in Hooghly
Computer Dealers in Hooghly
Laptop Dealers in Hooghly
Computer repair center in Hooghly