|
Barbara, what are the risks if the activation group ends and the files are
not yet closed?
Thanks
Marco
--- Barbara Morris <bmorris@xxxxxxxxxx> wrote:
>
> Here's a sketch of a module with a cleanup procedure.
>
> * Module HDLMYFILE
> H nomain
> Fmyfile if e disk usropn
> /copy prototypes
> D p s * inz(*null)
> P myproc b export
> /free
> if not %open(myfile);
> open myfile;
> endif;
> read myfile;
> if something ---
> eval p = %alloc(10);
> ---
> /end-free
> P e
>
> P hdlMyfile_cleanup...
> P b export
> /free
> // close files
> close *all;
> // free allocated storage
> if p <> *null;
> dealloc(n) p;
> endif;
> /end-free
> P e
>
> Here's how the main procedure of the program's uep module would look,
> along with the cleanup() procedure of the uep module.
>
> /free
> // enable cancel handler to ensure cleanup() is called
> // doing parameters by memory, maybe not exactly 3
> ceertx (%paddr(cleanup) : *omit : *omit);
>
> // do the function of the program
> --- whatever ---
>
> // cleanup
> cleanup();
> *inlr = '1';
> return;
> /end-free
>
> P cleanup b
> /free
> // cleanup submodules
> hdlMyfile_cleanup();
> queries_cleanup();
> reports_cleanup();
> whatever ('CLEANUP') // say you have a submodule with a main
> procedure
> // and 'CLEANUP' is the special parameter
> indicating
> // that it should just SETON LR and RETURN
>
> // cleanup this module's allocated storage if necessary
> // could also delete any temporary files or any other cleanup
> necessary
> if somepointer <> *null;
> dealloc(n) somepointer;
> endif;
> /end-free
> P e
>
> You might do similar processing for modules in service programs linked
> to your program, but a service program module might be "serving" more
> than just one program, so you might want a service program module to
> stay 'active' for your whole job.
>
> But as someone already said in this thread, you can get most of the
> cleanup done just by reclaiming the activation group.
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.