J joneden Active Member Licensed User Longtime User Nov 9, 2015 #1 Hi All, I have a shared code module that I use to store a lot of application variables such as icon names, standard dimensions, colours etc. As this list of the variables (and some constants) grows I am starting to ask myself if a list of variables is the best bet. For memory concerns would it be better to create these as functions that return the value rather than variables? Not knowing the way they are stored in memory I don't know which is best... Thanks for any advice. Regards Jon
Hi All, I have a shared code module that I use to store a lot of application variables such as icon names, standard dimensions, colours etc. As this list of the variables (and some constants) grows I am starting to ask myself if a list of variables is the best bet. For memory concerns would it be better to create these as functions that return the value rather than variables? Not knowing the way they are stored in memory I don't know which is best... Thanks for any advice. Regards Jon
JordiCP Expert Licensed User Longtime User Nov 9, 2015 #2 Unless I am missing something or misunderstood the question, there should not be perceivable memory differences on where are you declaring your vars. The big difference I see is in code readability/maintainability If your number of vars/constants is growing a lot, what I would do is to "group" these vars into types/structs (for those of them that makes sense), for instance create a type for all your vars/constants related to the UI of your app Code: Copy Type tUIVars( BackColor as Int, ForeColor as Int, IconName as String,....) Dim myUI as tUIVars '... Dim p as Panel '... p.Color=myUI.BackColor '... or even encapsulate them in classes would make sense if there are assotiated functions which involve these vars. Upvote 0
Unless I am missing something or misunderstood the question, there should not be perceivable memory differences on where are you declaring your vars. The big difference I see is in code readability/maintainability If your number of vars/constants is growing a lot, what I would do is to "group" these vars into types/structs (for those of them that makes sense), for instance create a type for all your vars/constants related to the UI of your app Code: Copy Type tUIVars( BackColor as Int, ForeColor as Int, IconName as String,....) Dim myUI as tUIVars '... Dim p as Panel '... p.Color=myUI.BackColor '... or even encapsulate them in classes would make sense if there are assotiated functions which involve these vars.
J joneden Active Member Licensed User Longtime User Nov 9, 2015 #3 Thanks for the response. That's a good idea about the types. I think that I'll give that a try. Regards Jon Upvote 0
Thanks for the response. That's a good idea about the types. I think that I'll give that a try. Regards Jon
Erel B4X founder Staff member Licensed User Longtime User Nov 9, 2015 #4 joneden said: For memory concerns would it be better to create these as functions that return the value rather than variables? Click to expand... The memory impact of such variables is insignificant. A single bitmap can take a few megabytes of ram. Lets say 4mb. This is equivalent to about 1 million integer variables. You should choose the simplest solution. Upvote 0
joneden said: For memory concerns would it be better to create these as functions that return the value rather than variables? Click to expand... The memory impact of such variables is insignificant. A single bitmap can take a few megabytes of ram. Lets say 4mb. This is equivalent to about 1 million integer variables. You should choose the simplest solution.
J joneden Active Member Licensed User Longtime User Nov 9, 2015 #5 haha put like that it does get it into perspective I'm too used to having to penny pinch because of underpowered devices (rugged units running 4.4.3)! Upvote 0
haha put like that it does get it into perspective I'm too used to having to penny pinch because of underpowered devices (rugged units running 4.4.3)!