[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] How to fclose()/fdelete() left open files from afl



PureBytes Links

Trading Reference Links

Title: Re: [amibroker] How to fclose()/fdelete() left open files from afl
Tomasz,
 
I frequently havve to use Global Variables from within functions, in order to "return" more than one variable.
 
Is the introduction of passing values by reference still in your plans, so we can write tighter code and still return more than one value from a function?
 
Thanks
 
ara
----- 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 -----
From: Herman
To: Herman
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




 


 

__._,_.___

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___