SKILL Q: "Tidy" Variables Instead of Globals

Discussion in 'Cadence' started by Edward, Oct 15, 2007.

  1. Edward

    Edward Guest

    I'm amassing quite a collection of global variables (mostly constants)
    for some of my routines. So now I'm considering consolidating these
    variables either into a global hash or perhaps into some sort of
    variable-serving function. Is anyone already familiar with these
    kinds of techniques? Can you share a small sample and your views on
    the subject?

    I'm leaning toward the variable-serving function (e.g.
    myGetVar("MPP_w")) solution. However, I'm wondering what kind of
    performance/memory hit to expect from setting a bunch of variables up
    only to produce the value for one of them at a time. Sure I'll have
    some global memory space clear, but this seems like it might be a bad
    way to go. Alternatively I've considered having all my variables in a
    global hash. I'm guessing this is what most people use to serve
    global vars for their various packages.
     
    Edward, Oct 15, 2007
    #1
  2. If you've got global variables, which are constants, then perhaps having some
    kind of package to do this might make sense. In SKILL++ you could do:

    myGlobalPackage=let((globalHash)
    globalHash=makeTable('globals)
    procedure(get(var) globalHash[var])
    procedure(set(var val) globalHash[var]=val)
    `(nil set ,set get ,get)
    )

    myGlobalPackage->set("const1" 23)
    myGlobalPackage->get("const1")

    The advantage of the above encapsulation is that you can change the
    implementation at a later date. However, this is probably overkill.
    Another possibility is just to take advantage of the fact that association
    tables can be used with the -> operator. For example:

    myGlobalVars=makeTable('globals nil)
    myGlobalVars->const1=23
    myGlobalVars->const1 => 23

    I wouldn't use this for all variables - just for things that really have to be
    global.

    Regards,

    Andrew.
     
    Andrew Beckett, Nov 15, 2007
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.