From: Mathias Gaunard on
On 16 jan, 19:25, ManicQin <manic...(a)gmail.com> wrote:

> When looking on projects and examples in the internet I find more and
> more "scoped" classes (RAII),
> ScopeGuard, ScopedTimer, ScopedBarrierEnd ,ScopedForking , auto_ptr
> (and his many friends) and the list is long...
>
> Now, when dropping the "re-scoping" of a class I can harm the -
> logical- flow of the code.

I fail to see how freeing some resources later than you could -- which
is what it means by removing the localized scope some RAII handlers
are in -- harms the logical flow of the code.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Nick Hounsome on
On 16 Jan, 19:25, ManicQin <manic...(a)gmail.com> wrote:
> Hello everybody,
> Let me explain what I mean,
>
> In my job I find many times the next "pattern"
>
> void foo()
> {
> //some code
> { //"re-scoping"
> char sTmp[256] = "";
> //some code
> }
> //some code
>
> }

Even without dtors there is a big difference between

{
char sTmp1[256] = ""; // arrays on the stack is a very bad idea
anyway!
//stuff
}
{
char sTmp2[256] = "";
//stuff
}

and the same without brackets.

Even a poor compiler knows that this only needs 256 bytes of stack
whereas a poor one might reserve 512 for an unbracketed version.



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]