Welcome, Guest. Please login or register.

Author Topic: ARexx: Use of external procedures  (Read 1571 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JettahTopic starter

  • Full Member
  • ***
  • Join Date: Nov 2003
  • Posts: 115
    • Show only replies by Jettah
ARexx: Use of external procedures
« on: December 10, 2004, 01:11:57 PM »
Hi,

I've written a rather lengthy ARexx-script, consisting of a huge number of external funktions. They are called this way:

CALL "REXX:GiveMeAUniqueNumber.rexx"
UniqueNumber = Result

Nothing wrong so far. But every time this funktion is called, it is loaded from disk into memory, which slows down the performance considerably.

Question:
Is there a way to keep that funktion in memory for the duration of the calling program?

Thanks,

Jettah
Sometimes I wish I was Mt Vesuvius: laying on my back in the sun while smoking a bit and everybody seeing me would say: \\"Look! He\\\'s active!\\" (author unknown to me)
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: ARexx: Use of external procedures
« Reply #1 on: December 10, 2004, 03:48:33 PM »
Quote
Is there a way to keep that funktion in memory for the duration of the calling program?

No. AFAIK the only way is to put the functions inside the same script file. Use procedures, like this:

/**/

say moo('test','foo')
exit

moo: procedure
  say 'numargs:' arg() 'args:' arg(1) arg(2)
  return 'moo ' || arg(1) || ' [' || arg(2) || '] !'

 

Offline Roj

  • Sr. Member
  • ****
  • Join Date: Jun 2002
  • Posts: 361
    • Show only replies by Roj
    • http://amiga.org/modules/mylinks/visit.php?lid=247
Re: ARexx: Use of external procedures
« Reply #2 on: December 10, 2004, 10:00:51 PM »
Here's an overview of a way to make external functions like this run a little faster if you really need to keep them external.

When your program starts, create a message port that'll be used by the external routines to return their data. Then each external function would open its own message port and wait for a packet. When a message arrives at the external function's message port, run your function and return the data to the main program's message port.


Here's an example. Start TimeStampServer.rexx, then start TimeStampMain.rexx.

You'll get output something like this:

00.01.49.06
00.01.49.08
00.01.49.10
00.01.49.12
00.01.49.12

Hope it helps.


-- Begin file TimeStampMain.rexx --
Code: [Select]

  /* Time Stamp Main */

  DO FOR 5
    PortHandle = OPENPORT('TIMESERVERREPLYPORT');
    ADDRESS 'TIMESERVER' 'GETTIME'
    CALL WAITPKT('TIMESERVERREPLYPORT')
    Packet = GETPKT('TIMESERVERREPLYPORT')
    Output = GETARG(Packet)
    CALL REPLY(Packet, 0)
    CALL CLOSEPORT('TIMESERVERREPLYPORT')
    SAY Output
  END

-- End file TimeStamp.rexx --

-- Begin file TimeStampServer.rexx --
Code: [Select]

  /* Time Stamp Server */

  PortHandle = OPENPORT('TIMESERVER')
  CALL TIME('RESET')
  DO UNTIL UPPER(Status) = 'QUIT'
    CALL WAITPKT('TIMESERVER')
    Packet = GETPKT('TIMESERVER')
    IF Packet ~= NULL() THEN
      DO
        Status = GETARG(Packet)
        CALL REPLY(Packet, 0)
        IF UPPER(Status) = 'GETTIME' THEN
          DO
            TimeValue = TIME('ELAPSED')
            Seconds = TimeValue // 60
            Minutes = (TimeValue % 60)
            Hours = Minutes % 60
            Minutes = Minutes // 60
            TimeValue = RIGHT(Hours,   2, '0') || '.' ||,
                        RIGHT(Minutes, 2, '0') || '.' ||,
                        RIGHT(TRUNC(Seconds, 2), 5, '0')
            ADDRESS 'TIMESERVERREPLYPORT' TimeValue
          END
      END
  END
  CALL CLOSEPORT('TIMESERVER')

-- End file TimeStampServer.rexx --
I sold my Amiga for a small fortune, but a part of my soul went with it.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: ARexx: Use of external procedures
« Reply #3 on: December 11, 2004, 12:44:09 AM »
@Roj

Oh that's great stuff, indeed that should be a lot faster than calling external script every time.
 

Offline JettahTopic starter

  • Full Member
  • ***
  • Join Date: Nov 2003
  • Posts: 115
    • Show only replies by Jettah
Re: ARexx: Use of external procedures
« Reply #4 on: December 11, 2004, 11:16:54 AM »
@Roj

Hey, that's a great way of doing things! Be sure that I'm going to try this. Thanks for this brilliant idea.

Regards,

Jettah
Sometimes I wish I was Mt Vesuvius: laying on my back in the sun while smoking a bit and everybody seeing me would say: \\"Look! He\\\'s active!\\" (author unknown to me)