----- Original Message -----
Sent: Thursday, October 30, 2008 7:33
AM
Subject: Re: [amibroker] How to
fclose()/fdelete() left open files from afl
Herman,
Best method to avoid problems,
interdependenices is to
open file, do the reading/writing you need
and close the file all within ONE funciton.
Don't worry too much about the open/close
performance as system caches file access and you are not
really accesing disk file physically, but its
file system virtual cache in RAM.
Do not keep files open between functions, all
file operation should be encapsulated in one function
that does the job.
You should keep dependencies between
functions at lowest possible level (ideal: zero).
Funcitons should only communicate via one
entry point (input parameters) and one defined result.
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
Sent: Thursday, October 30, 2008
3:19 PM
Subject: Re: [amibroker] How to
fclose()/fdelete() left open files from afl
I am now using this, somewhat awkward, method to monitor file
open/close operations. I wrapped fopen() with xfopen() and fclose() with
xclose().
I post this just in case someone has similar debugging problems.
Herman
function Trace( Msg )
{
TraceEnabled = Nz( StaticVarGet( "TraceEnabled" )
);
if ( TraceEnabled )
_TRACE( Msg );
}
function TRACEONCE( Msg )
{
TraceEnabled = Nz( StaticVarGet( "TraceEnabled" )
);
if ( TraceEnabled
)
{
PrevMessage = StaticVarGetText(
"LastTraceMsg" );
if (
PrevMessage != Msg )
{
_TRACE( Msg );
StaticVarSetText(
"LastTraceMsg", Msg );
}
}
}
function xfopen( filename, mode )
{
fh = fopen( filename, mode );
StaticVarSetText("FM"+fh, filename + " Mode: "+Mode
);
TraceOnce("FILE Opened: "+ filename+ " Mode:
"+Mode);
return fh;
}
function xfclose( Handle )
{
fclose( Handle );
FileMode = StaticVarGetText("FM"+Handle );
TraceOnce("FILE Closed: "+ FileMode );
}
Thursday, October 30, 2008, 8:46:25 AM, you wrote:
> |
It often happens during development that, due
to coding errors, files are not closed. The only way to close
these file appears to be to use an external UnLock program to
UnLock and delete the file. Since I use many files it is very time
consuming to locate the open files and the afl errors that caused
them.
I'd like advice from experienced programmers
on how to detect, locate, and close files left open due to
mistakes, from afl of course.
many thanks for any suggestions you may
have,
herman
|