How are string parameters handled in Control?

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
3 posts • Page 1 of 1
a.decelis
Posts:30
Joined: Thu Jun 25, 2015 6:42 pm

How are string parameters handled in Control?

Post by a.decelis »

Hello there,

This question is neither a problem, nor a bug.

I was wondering about memory-intensive parameters. Let's say we have:

Code: Select all

myFun1(string param)
{
    DebugN("This is function myFun1 and param=", param);
}
Will this other version more efficient?

Code: Select all

myFun2(const string &param)
{
    DebugN("This is function myFun2 and param=", param);
}
In either functions, the parameter is used read-only.
I was wondering if, internally, the interpreter, for myFun1, is actually creatring a whole new string variable and copying the passed value onto it, or param is just an internal reference to the original string, with a copy-on-write policy.
Whatever is happening under the hood, I would like to know if is "myFun2" more efficient than "myFun1"? (In terms of memory ussage, I expect a parsing overhead for myFun2)

It is my understanding that dynamic-size types, like dyn_string or mappings are to be passed as const& when no modifications are to be made. Am I right?

Regards,

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: How are string parameters handled in Control?

Post by mkoller »

Yes, the const reference version is more efficient, since the copy is not done. This is true for all datatypes.

a.decelis
Posts:30
Joined: Thu Jun 25, 2015 6:42 pm

Re: How are string parameters handled in Control?

Post by a.decelis »

Thanks for the information!

3 posts • Page 1 of 1