Article View: borland.public.cppbuilder.nativeapi
Article #802Re: ensuring CriticalSections are release..
From: Clayton Arends
Date: Mon, 14 Jan 2008 18:40
Date: Mon, 14 Jan 2008 18:40
60 lines
2938 bytes
2938 bytes
"Dennis Jones" <nospam@nospam.com> wrote in message
news:478b0076$1@newsgroups.borland.com...
> An article discussing the implementation and use of ScopeGuard was written
> by Andrei Alexandrescu and Petru Marginean and was published in CUJ in
> December 2000.
Nice article.
I had always been a little disappointed with pure RAII techniques since it
seemed silly to have to make full class every time a new use situation
arose. I stuck with it though (and occassionally slipped in a well
documented try...__finally block).
After testing ScopeGuard I might make the switch. It even works with
closures.
I have one itty bitty problem with using this approach. I haven't looked
closely enough yet to see why it's happening. If full warnings are enabled
(specifically -w-aus) and I use a standard RAII class (like std::auto_ptr or
something I've made) then the following compiles in Builder without warning
(in BCB6 and CB2007):
class TMyAuto
{
private:
char* Ptr;
public:
TMyAuto(char* APtr) : ptr(APtr) {}
~TMyAuto() { delete Ptr; }
};
char* c = new char;
TMyAuto auto_c(c);
// This also works with no warning
// std::auto_ptr<char> auto_c(c);
However, if I use ScopeGuard I receive a W8004 warning:
void DeleteIt(char* Ptr)
{
delete Ptr;
}
char* c = new char;
ON_BLOCK_EXIT(&DeleteIt, c);
// This also causes a W8004 warning
// ScopeGuard auto_c(MakeGuard(&DeleteIt, c));
W8004 'scopeGuard321' is assigned a value that is never used
As I said above I haven't looked too much into this. I don't know if
Builder should be mentioning the warning in all cases or if it follows some
rule that ScopeGuard isn't triggering. In any case, I still like ScopeGuard
and will investigate the warning issue at a later date.
Clayton
Technical Details
Message-ID:
<478bac9a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<478a96e3@newsgroups.borland.com> <478b0076$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,266d339b0fd4ba38 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Clayton Arends" <nospam_claytonarends@hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <478a96e3@newsgroups.borland.com> <478b0076$1@newsgroups.borland.com> In-Reply-To: <478b0076$1@newsgroups.borland.com> Subject: Re: ensuring CriticalSections are release.. Date: Mon, 14 Jan 2008 10:40:10 -0800 Lines: 61 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6000.16480 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16545 NNTP-Posting-Host: 68.113.27.46 Message-ID: <478bac9a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1200336026 68.113.27.46 (14 Jan 2008 10:40:26 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail