From: Tobias Boege <tabo...@gmail.com> > Yeah, may I throw in some related thought? > > I know you asked for the most efficient way to do it but your program > should > also be safe from race conditions, right? When you do > > ' Check for existance > If Exist(sPath) Then Kill sPath > > or even > > ' Check for existance and write access using short-circuit > If Exist(sPath) And If Stat(sPath).Auth Like "?w*" Then Kill sPath well the safe for race conditions at this point dont care to much, but u'r response are very interesting
> Let's also consider what most probably happens at least under Linux when > you > have Try Kill sPath in Gambas (note that I didn't consult the real sources > here, just guessing how it would be done): the interpreter will call the > unlink() syscall which deletes the file or delivers an error. The error is > propagated but suppressed by Try. > > With Exist(sPath) Then Kill sPath, the interpreter likely executes > something > like access() which can equivalently well fail or succeed. If it succeeds > you still have to do the same unlink() operation. > > So, the best case you can get is that Exist() is false. Then the running > time is roughly access() vs. unlink(). In all other cases, the Try Kill > approach seems to be faster and safer, too. > > You have to decide now: Do you expect sPath non-existing most of the time? > Do you want to ignore race conditions in favour of performance? Then use > the > If Exist(...) Then Kill ... method. i like the way u defeat the try-cach.. umm but mi questio are due try-cach internals rutines have more code to compute the race conditions, rather than if-else, so due if-else do not compute the race contidions obviously are more faste, of course also more insegure! that's all.. i currently use if-else, due write disk i already check at start time and each day but as u done, recomended its to use try-catch > > Regards, > Tobi > > -- -- Lenz McKAY Gerardo (PICCORO) http://qgqlochekone.blogspot.com ------------------------------------------------------------------------------ November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user