Home AMX User Forum NetLinx Studio

Volatile vs Non-volatile

Hi,

Except more memory available, what are the benefits of using volatile memory instead of non-volatile memory in NetLinx? Faster Speed?


Cheers,
Charles

Comments

  • frthomasfrthomas Posts: 176
    VOLATILE (the meaning of the Netlinx keyword) only means the global variable value is not kept in between "runs" of the master, i.e. if you restart it the value is retained.
    In practice it seems Netlinx uses a normal (VOLATILE) variable for it and refreshes it at startup (you can see it done in the log) and I imagine stores it back into NVRAM at reboot time.

    Hence there is no performance difference. The amount of PERSISTENT memory is however limited, hence the need to indicate which variables are worth keeping and which aren't.

    There is another post where the poster referred to non-volatile memory used by modules but I don't quite see what he meant.

    As a general note, I'd say it does not really matter performance wise which type of variable is used, in general it is all implemented in the same way with just the COMPILER taking care or advantage of the constraints. A constant for example COULD be implemented as a standard variable you can't change the value of from within your program (i.e. if no instructions change it in the final code generated by the compiler, it is constant...)

    Fred
  • NetLinx Memory

    I posted this in another topic, but it goes well here also.

    Unless you _EXPLICITLY_ define a variable as VOLATILE, it will be placed in the non-volatile memory by default. This was done to maintain backwards compatability with Axcess behavior.

    Things like buffers and any variable or structures that are initialized every time probably should be declared as VOLATILE to help reduce the unnecessary use of non-volatile memory (since it is limited compared to volatile).

    FYI Firmware and compiled NetLinx code are loaded into volatile memory at start time, so the size of your program can affect the amount of free volatile memory. In all but extreme cases, there is usually plenty of volatile memory, so if you run out of non-volatile memory, look at what probably should be volatile and explicitly declare it to be volatile.

    It may be overstating the obvious, but anything PERSISTENT cannot be VOLATILE.

    To answer your specific question, Volatile and non-volatile memory do run out of different memory. Theoretically, volatile memory should be faster. But in reality, I doubt you could notice a difference in performance.

    HTH,
    Chuck
  • frthomasfrthomas Posts: 176
    Re: NetLinx Memory
    Originally posted by cwpartridge
    Volatile and non-volatile memory do run out of different memory.

    So if I may, out of curiosity, what is this business in the system log about "restoring persistent variables"? I mean, if the persistent vars are accessed from the code in NVRAM directly (or whatever it is that's used), why "restore" it at startup time?

    Thanks

    Fred
  • Good question.

    We must start by looking at what happens when a new program has been loaded on the master and the master is rebooted.

    When the master detects that the program it is loading is different than the last one it ran, it has no idea what PERSISTENT variables are in the old program. It knows it must save the PERSISTENT variables that were in the old program, in case they are in the new program. It does the following:

    - Make a copy of all PERSISTENT variables in NV memory and place that copy where it will not be overwritten when loading the new program.

    - Load the new program. This puts any NV variables in the new program into NV memory. The PERSISTENT variables in the new program could be the same PERSISTENT variables it copied earlier, an entirely new set of PERSISTENT variables, or a subset of those two (some old,some new).

    - It now restores any PERSISTENT variables that where in the old and new program to the value that was in the copy. This is done by variable name, so if the names changed between the old and new, it is not resored.

    - After all old PERSISTENT variables are checked, the copy is deleted.

    HTH,
    Chuck
Sign In or Register to comment.