Question on global variables
-
Good morning,
Do you know how many variables can be created? and what kind of memory do they use? i.e. where are they stored?
On the other hand, the var type variables, if within a macro1 I call another macro2 with M98 and in this macro2 I create var type variables I can use them in macro1, that is to say, when these are deleted? at the end of all routines and sub routines or only serve for each macro?
Best regards
-
@aitor I can't answer your first questions. As for the second part, according to the wiki https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Variables
it states " The scope of a local name is the remainder of the block in which it is declared." -
@aitor If you like to use a var in different macros, you can define a global variable.
-
Good morning @DECKINGMAN,
I've already read it, but it's not clear to me, I don't know if it's because of the translation or because I don't understand what you mean by "block".
And in a way, as I understand it, if we put the example the other way round, that is, in macro1 I declare the variables and use them in macro2, in principle the block of macro1 has not finished, right?
Good morning @COSMOWAVE,
Yes, I know, but I'm starting to have a lot of them, but if I can save some of them, my config will be much cleaner.
-
-
@aitor said in Question on global variables:
And in a way, as I understand it, if we put the example the other way round, that is, in macro1 I declare the variables and use them in macro2, in principle the block of macro1 has not finished, right?
Variable declared using var are local to the block and file in which they are declared. So variables declared in a calling macro are not available in the called macro. However, parameters can be passed to macros.
-
@dc42 said in Question on global variables:
@aitor said in Question on global variables:
And in a way, as I understand it, if we put the example the other way round, that is, in macro1 I declare the variables and use them in macro2, in principle the block of macro1 has not finished, right?
Variable declared using var are local to the block and file in which they are declared. So variables declared in a calling macro are not available in the called macro. However, parameters can be passed to macros.
good morning @dc42,
as for the number of global variables that can be created, is there any limit?
Un saludo
-
@aitor said in Question on global variables:
as for the number of global variables that can be created, is there any limit?
The limits are:
- Available RAM on the Duet. You can check the "Never used RAM" value reported by M122.
- If you create a very large number of them, then an object model query to report all global variables might fail because of lack of output buffer space.
-
@dc42 said in Question on global variables:
@aitor said in Question on global variables:
as for the number of global variables that can be created, is there any limit?
The limits are:
- Available RAM on the Duet. You can check the "Never used RAM" value reported by M122.
- If you create a very large number of them, then an object model query to report all global variables might fail because of lack of output buffer space.
sorry @dc42, this raises new doubts in my mind.
How much free memory is recommended for a good performance?
the question before, of the macros was to use echo >> to save variables var type in a file and call them when necessary, and not occupy memory, I'll give it a spin in case I can think of something, to avoid some variables.
on the other hand, I could not check it in 3.4beta3 M122, I do not inform
-
@aitor said in Question on global variables:
How much free memory is recommended for a good performance?
When "never used RAM" runs out, the machine is in danger of resetting with an Out Of Memory fault if you do something that needs more RAM. So aim to have a few kb spare after you have done a print. Performance is not affected by the amount of free RAM as long as it hasn't run out.