Real information about Unreal Engine 3

Saturday, February 23, 2013

Name vs. String

If you are new to UnrealScript, you may wonder what the difference between Names and Strings is and when you should use Names instead of Strings. This article will give you some information about that.

Limitation

 

Names are unmodifiable. You can't cut down the string values of Names like Strings, but you can assign a Name variable to a new value.

Names are restricted to up to 1024 characters, and Name constants allow only alphanumeric characters or underscores. However, you can make a Name variable containing non-alphanumeric characters by converting a string to it like the following.
ANameVar = name(":>");
However, you can't use this technique in ini files. So if you want non-alphanumeric characters in your strings, you might think to use Strings. For example, there are many String variables in Engine.uc for the names of configurable classes. This is because a full class name is like "MyPackage.MyClass". There is a dot in the middle.

Cost and Performance

 

Actually each Name variable stores an index to a global name table. If two Name variables have the same value, they will store the same index. So if you have a string appearing everywhere, it may be a good choice to put it into Names. This may save you some memory space but introduce some overhead to look up the string in the name table when Names are created. On the other hand, if you need a string variable and you want to modify its value multiple times at runtime, you may think to use a String variable instead of a Name because the name table is kept until the program is closed. Names may end up totally taking up more space than Strings are in some cases.

However, Names are fast to copy and pass to functions. On the contrast, if you pass Strings by value in UnrealScript, the string values will be duplicated (deep copy) and the passing will take more space than Names will. However, you can pass Strings by const out just like const reference in C++ to avoid that.

0 comments :

Post a Comment

Followers

AD (728x90)

Powered by Blogger.