CTL keyword ? 
Author Message
 CTL keyword ?

Quote:

> I use :
> DCL POINTER_TABLE(*) CONTROLLED PTR;
> And when I run I get a protection exception whenever
> there's an assignment to this table.

You need 'ALLOC POINTER_TABLE(200);' (or whatever size you want) before
you reference it.  CTL storage, among other advantages, allows for
dynamic sizing of arrays or strings at run time.  You could also then
free it when you're done with it to allow the storage to be reused.


Mon, 01 Oct 2001 03:00:00 GMT  
 CTL keyword ?


Quote:
> >  Dcl A fixed bin(15) controlled;
> >  Do I = 1 to 100;
> >   ALLOCATE A;

> I'm not sure why I can't do this w/o controlled....

you can, what this code implies is that you want 100 versions of variable A,
but you only want to access the last one at any one time, in other words
it's a push down stack, for ex (a very noddy piece of code !)

/* LOAD IT UP !*/
DO I=1 TO 100 ;
       ALLOC A;
       A = I ;
END ;

/*PRINT IT OUT */
DO I=1 TO 100;
      PUT SKIP LIST(A) ;
      FREE A;
END ;

Should print 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.

Each alloc stmt acquires new storage (getmain) and each free free's off the
current storage for A, making the last one available again.

A slightly more sophisticated way of coding the second loop is to use the
ALLOCATION (or ALOCN) builtin function as in:

DO I=1 TO ALLOCN(A);
      PUT SKIP LIST(A) ;
      FREE A;
END ;

Allocn returns the number of 'generations' or 'versions' of a controlled
variable that currently exist.



Wed, 03 Oct 2001 03:00:00 GMT  
 CTL keyword ?

Quote:



> > >  Dcl A fixed bin(15) controlled;
> > >  Do I = 1 to 100;
> > >   ALLOCATE A;

> > I'm not sure why I can't do this w/o controlled....

> you can, what this code implies is that you want 100 versions of variable A,
> but you only want to access the last one at any one time, in other words
> it's a push down stack, for ex (a very noddy piece of code !)

> /* LOAD IT UP !*/
> DO I=1 TO 100 ;
>        ALLOC A;
>        A = I ;
> END ;

> /*PRINT IT OUT */
> DO I=1 TO 100;
>       PUT SKIP LIST(A) ;
>       FREE A;
> END ;

> Should print 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.

> Each alloc stmt acquires new storage (getmain) and each free free's off the
> current storage for A, making the last one available again.

> A slightly more sophisticated way of coding the second loop is to use the
> ALLOCATION (or ALOCN) builtin function as in:

> DO I=1 TO ALLOCN(A);
>       PUT SKIP LIST(A) ;
>       FREE A;
> END ;

> Allocn returns the number of 'generations' or 'versions' of a controlled
> variable that currently exist.

I'm not sure that "TO ALLOCN(A)" above is re-evaluated after the first
iteration.  A safer way would be...

DO WHILE(ALLOCN(A)>0);
   ...
   FREE A;
   END;



Wed, 03 Oct 2001 03:00:00 GMT  
 CTL keyword ?



Quote:



> > > >  Dcl A fixed bin(15) controlled;
> > > >  Do I = 1 to 100;
> > > >   ALLOCATE A;

> > > I'm not sure why I can't do this w/o controlled....

> > you can, what this code implies is that you want 100 versions of
variable A,
> > but you only want to access the last one at any one time, in other words
> > it's a push down stack, for ex (a very noddy piece of code !)

> > /* LOAD IT UP !*/
> > DO I=1 TO 100 ;
> >        ALLOC A;
> >        A = I ;
> > END ;

> > /*PRINT IT OUT */
> > DO I=1 TO 100;
> >       PUT SKIP LIST(A) ;
> >       FREE A;
> > END ;

> > Should print 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.

> > Each alloc stmt acquires new storage (getmain) and each free free's off
the
> > current storage for A, making the last one available again.

> > A slightly more sophisticated way of coding the second loop is to use
the
> > ALLOCATION (or ALOCN) builtin function as in:

> > DO I=1 TO ALLOCN(A);
> >       PUT SKIP LIST(A) ;
> >       FREE A;
> > END ;

> > Allocn returns the number of 'generations' or 'versions' of a controlled
> > variable that currently exist.

> I'm not sure that "TO ALLOCN(A)" above is re-evaluated after the first
> iteration.  A safer way would be...

> DO WHILE(ALLOCN(A)>0);
>    ...
>    FREE A;
>    END;

I am sure, "TO ALLOCN(A)", wouldn't need to be re-evaluated each time, and
wouldn't be. When the "DO I=" statement is initially executed, I is set to
ALLOCN(A), in this case 100. during the second and subsequent iterations
ALLOCN(A), would not be re-evaluated, there is no need, the end-condition
for this iterative do specification has already been established, at the
start of the entire process. So you would get (in this case) 100 iterations.

So your code fragment is functionally the same, in both cases you would get
exactly ALLOCN free's, and no free would be executed when ALLOCN(A)=0.

Steve Havercroft



Wed, 03 Oct 2001 03:00:00 GMT  
 CTL keyword ?

Quote:






> > > > >  Dcl A fixed bin(15) controlled;
> > > > >  Do I = 1 to 100;
> > > > >   ALLOCATE A;

> > > > I'm not sure why I can't do this w/o controlled....

> > > you can, what this code implies is that you want 100 versions of
> variable A,
> > > but you only want to access the last one at any one time, in other words
> > > it's a push down stack, for ex (a very noddy piece of code !)

> > > /* LOAD IT UP !*/
> > > DO I=1 TO 100 ;
> > >        ALLOC A;
> > >        A = I ;
> > > END ;

> > > /*PRINT IT OUT */
> > > DO I=1 TO 100;
> > >       PUT SKIP LIST(A) ;
> > >       FREE A;
> > > END ;

> > > Should print 10, 9, 8, 7, 6, 5, 4, 3, 2, 1.

> > > Each alloc stmt acquires new storage (getmain) and each free free's off
> > > the current storage for A, making the last one available again.

> > > A slightly more sophisticated way of coding the second loop is to use
> > > the ALLOCATION (or ALOCN) builtin function as in:

> > > DO I=1 TO ALLOCN(A);
> > >       PUT SKIP LIST(A) ;
> > >       FREE A;
> > > END ;

> > > Allocn returns the number of 'generations' or 'versions' of a controlled
> > > variable that currently exist.

> > I'm not sure that "TO ALLOCN(A)" above is re-evaluated after the first
> > iteration.

The TO option (like the initial value) is evaluated once only
prior to execution of the loop.

As ALLOCATON returns the number of allocations, it is
only necessary to evaluate it once anyway.

Quote:
>  A safer way would be...

> > DO WHILE(ALLOCN(A)>0);

re-evaluations of ALLOCATION waates time, and therefore
would be less efficient than the original version using DO  ..  TO.

- Show quoted text -

Quote:
> >    ...
> >    FREE A;
> >    END;

> I am sure, "TO ALLOCN(A)", wouldn't need to be re-evaluated each time, and
> wouldn't be. When the "DO I=" statement is initially executed, I is set to
> ALLOCN(A), in this case 100. during the second and subsequent iterations
> ALLOCN(A), would not be re-evaluated, there is no need, the end-condition
> for this iterative do specification has already been established, at the
> start of the entire process. So you would get (in this case) 100 iterations.

> So your code fragment is functionally the same, in both cases you would get
> exactly ALLOCN free's, and no free would be executed when ALLOCN(A)=0.

> Steve Havercroft



Wed, 03 Oct 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. extracting keywords from %(keyword)s-based templates

2. passing keyword arguments that are themselfs python keywords

3. Laser.ctl files - Print problem

4. Ctl Main Error GPF

5. CTL Main 05

6. Internal error 05 : CTL MAIN

7. CD3102, PRINTER.CTL, XTRACE.TXT

8. CPD Printer controls .CTL

9. Point of Sale Software/with Inventory Ctl.

10. costanti originate da typedef non aggiornano a variazione ctl origine

11. Application Builder: Error 1 occurred at EventData.ctl

12. FP Control inheriting the .ctl documentation

 

 
Powered by phpBB® Forum Software