Re: passing parameter by reference?



Lisa Pearlson wrote:
... in essence it's 1 process listening on several sockets simultaneously and as such the global variables are shared among all those clients.. somehow I would have to keep an associative array with the key being the socket descriptor and value being an array of variables I wish to track for each client, such as a timerid for the idle timeout handling of each connection, etc. This is too much overhead I think.

It's not that much overhead. Something simple along the lines of:

proc readData {chan ...} {
    global state
    puts "The timeput on $chan is $state($chan,timeout)"
    ...
}

That should work fine, and is an approach I have used on several occassions.

As you are using fileevents, another method is to reschedule the fileevent with the updated state:

proc readData {chan chanState ...} {
    array set state $chanState
    puts "The timeout on $chan is $state(timeout)"
    ...
    fileevent $chan readable \
      [list readData $chan [array get state]...]
}

Which is quite neat in some ways (e.g. closing the channel will delete the fileevent and automatically clean up the state for you), but I'd probably go with the global array first.

-- Neil
.



Relevant Pages

  • Re: Using collection to store variable values
    ... store variables rather than declaring Global Variables. ... and a value or a key (to retrieve the value). ... that functionality is working fine in the test program I've developed. ... The problem with using an array is that you either have to keep track of ...
    (microsoft.public.access.formscoding)
  • Re: Globals vs passing in by reference
    ... >hold this array. ... Then they increment the global int variable. ... >function or just access the global variables? ... probably) and the counter has a cost in ...
    (comp.lang.c)
  • Re: Using collection to store variable values
    ... store variables rather than declaring Global Variables. ... and a value or a key (to retrieve the value). ... that functionality is working fine in the test program I've developed. ... The problem with using an array is that you either have to keep track of ...
    (microsoft.public.access.formscoding)
  • Re: Global User Defined Array?
    ... Thanks for the heads up Mike. ... Been programming for about 2 years now. ... global variables you wind up with too many variables in the whole project ... In this case though I only needed one array to be global. ...
    (microsoft.public.vb.controls)
  • Re: passing data to functions in other units
    ... > From what j said each unit can access the global variables provided the ... >> There are three passing mechanisms in Delphi that you should consider. ... The routine is therefore working with the ... >> array to find the middle value and didn't want to sort the passed array, ...
    (alt.comp.lang.borland-delphi)