Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User Defined Function Structure
#1
Hi All,
I have many user-defined functions of the form:

Function NameRectifier
Code:
Copy      Help
function str&UserLogin str&UserLastName str&UserFullName
,
if UserLogin = "jkj1";
,UserLastName= "Jones"; err ret
,UserFullName= "Jonathan K Jones"; err ret

if UserLogin = "sps45";
,UserLastName= "Smith"; err ret
,UserFullName= "Sam P Smith"; err ret    
,
if UserLogin = "";
,UserLastName= ""; err ret
,UserFullName= ""; err ret
,
if UserLogin = "";
,UserLastName= ""; err ret
,UserFullName= ""; err ret

etc, etc, going on for even up to potentially >100 entries

I use these functions to link computer names to adjacent phone numbers, ip addresses, etc and to swap technical names scraped from document metadata into common names, etc.
They work perfectly fine but I was just wondering if there was a more elegant or easier to maintain or perhaps faster-executing way to organize these.
I figure there is probably an xml answer but that may not run as fast as just having them all in a long function within QM rather than an external file. Should I be creating a multi-dimensional array? Anyway, I have learned so much about about programming style just by customizing Gintaras' and other's many examples in the Forum so I thought I might ask.

Stuart
#2
I think xml embedded in the function would be fast enough. Or use simple list, maybe with IStringMap, but then needs more code to parse, escape/unescape. Or use sel.
#3
Thanks Gintaras, I looked at sel case and IStringMap interfaces as well as re-examined xml.

I see the advantage of using Xml. I can create dialogs to ease entry of the users database and even have the user populate the information themselves by a user friendly document which will create the user child elements and its attributes.

Function Function8
Code:
Copy      Help
out
IXml MyUsersXml=CreateXml

IXmlNode MyUsers=MyUsersXml.Add("Users") ;;add root element (XML must have exactly 1 root element)

IXmlNode IndivUserData=MyUsers.Add("jkj1")
IndivUserData.SetAttribute("LoginName" "jkj1") ;;add attribute
IndivUserData.SetAttribute("LastName" "Jones") ;;add another attribute
IndivUserData.SetAttribute("Full Name" "Jonathan K Jones") ;;add another attribute
;
IndivUserData=MyUsers.Add("sjs1")
;
IndivUserData.SetAttribute("LoginName" "sjs1") ;;add attribute
IndivUserData.SetAttribute("LastName" "Smith") ;;add another attribute
IndivUserData.SetAttribute("Full Name" "Sam J Smith") ;;add another attribute
;
IndivUserData=MyUsers.Add("wje1")
;
IndivUserData.SetAttribute("LoginName" "wje1") ;;add attribute
IndivUserData.SetAttribute("LastName" "Edwards") ;;add another attribute
IndivUserData.SetAttribute("Full Name" "William J Edwards") ;;add another attribute


;;
MyUsersXml.ToFile("$qm$\MyUsers.xml")
;

out "-----"
str s
MyUsersXml.ToString(s) ;;compose xml string
out s
This creates this Xml structure

Quote:-----
<Users>
<jkj1 LoginName="jkj1" LastName="Jones" Full Name="Jonathan K Jones" />
<sjs1 LoginName="sjs1" LastName="Smith" Full Name="Sam J Smith" />
<wje1 LoginName="wje1" LastName="Edwards" Full Name="William J Edwards" />
</Users>


My question now is about speed. The user defined functions are accessed multiple times over and over. It would seem to be slow if QM had to access either a local or network file each time to get the various elements. Is it possible to populate a user defined function like I originally queried about but instead of it already being in the qml file, it gets populated from an Xml file only at the time of QM startup or loading/updating of a specific qml file?


Thanks!!!!

Stuart
#4
Possible with newitem, except in exe.

Or use global IXml variable. Load when QM starts etc.
#5
I wouldn't want to put a stress on pc resources with many global variables too large
The largest macro (I exported it singly) is about 12 kb as a separate qml export but there could be several of these.
Do you recommend having so many of these global variables sitting around in QM's memory allocation. Would this potentially increase instability/crashes.
The newitem seems like a safe way to go. Is there any downsides?

Thanks so much,
Stuart
#6
QM IXml objects don't eat so much memory. About the same amount as the macro. Also similar speed.
#7
So if I undestand your answer correctly, when something is a global variable, it's not that it necessarily takes up more memory than a local variable, it's just that QM.exe keeps reference to it between macros (i.e. the pointer not the full size of what's stored in the global variable - is what's preserved when you use global variable). If that's the case, then I will create these globally at qm startup!
I hope I explained my weak understanding of this somewhat correctly.
Stuart
#8
Whole object and its data (XML) always is in memory. Macro text also always is in memory. If compiled, multiply by 2 o 3.
#9
Thanks for clearing this up!
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)