OSNews article about C++09 degenerates into C++ vs. D discussion

David Medlock noone at nowhere.com
Tue Nov 21 18:20:49 PST 2006


Boris Kolar wrote:
> == Quote from Walter Bright (newshound at digitalmars.com)'s article
> 
>>No. But most RAII usage is for managing memory, and Boris didn't say why
>>he needed RAII for the stack allocated objects.
> 
> 
> Mostly for closing OS handles, locking, caching and stuff. Like:
>   getFile("a.txt").getText()
> 
> Normally, one would have to:
>   1. open the file (which may allocate caching buffers, lock the file, etc.)
>   2. use the file (efficiently)
>   3. close the file (frees handles, buffers, releases locks, etc.)
> 
> It's a common design pattern, really.

I know Sean suggested scope (RAII) but how about:

File file = new FileStream(...);
scope(exit) { file.close(); }
...

-DavidM



More information about the Digitalmars-d mailing list