Amiga.org
Amiga computer related discussion => Amiga Software Issues and Discussion => Topic started by: Jettah 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
-
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) || '] !'
-
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 --
/* 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 --
/* 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 --
-
@Roj
Oh that's great stuff, indeed that should be a lot faster than calling external script every time.
-
@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