Urho3D implements its own string type and template containers instead of using STL. The rationale for this consists of the following:

    Increased performance in some cases, for example when using the PODVector class. Guaranteed binary size of strings and containers, to allow eg. embedding inside the Variant object. Reduced compile time. Straightforward naming and implementation that aids in debugging and profiling. Convenient member functions can be added, for example String::Split() or Vector::Compact(). Consistency with the rest of the classes, see Coding conventions. The classes in question are String, Vector, PODVector, List, HashSet and HashMap. PODVector is only to be used when the elements of the vector need no construction or destruction and can be moved with a block memory copy.

    The list, set and map classes use a fixed-size allocator internally. This can also be used by the application, either by using the procedural functions AllocatorInitialize(), AllocatorUninitialize(), AllocatorReserve() and AllocatorFree(), or through the template class Allocator.

    In script, the String class is exposed as it is. The template containers can not be directly exposed to script, but instead a template Array type exists, which behaves like a Vector, but does not expose iterators. In addition the VariantMap is available, which is a HashMap.

    Urho3D实现了属于它自己独有的字符串类型和模板容器,用来代替STL。原因如下:

    • 提高某些情形下的效率,比如使用PODVector类。
    • 保证了字符串和容器的二进制大小,使其可以被Variant对象所包含。
    • 减少编译时间
    • 直白的命名和实现,帮助你更好地调试和理解。
    • 添加了一些方便的方法,比如String::Split()和Vector::Compact()。
    • 与其他类一样,保证代码规范,请参考Coding conventions(代码规范)部分。

    相关的类型有String, Vector, PODVector, List, HashSet和HashMap。PODVector是一个专门用于存储POD类型的Vector。

    List, Set, Map类在内部使用了固定大小的内存分配方式。这样已经可以在程序中正常使用了,不过你也可以自己使用AllocatorInitialize(), AllocatorUninitialize(), AllocatorReserve(), AllocatorFree()或者模板类Allocator去分配内存块。

    在脚本中可以直接使用String类型,但是由于模板容器不能直接被暴露在脚本中,仅存在一个模板类型Array(类似Vector,但是没有暴露迭代器)。另外还可以使用VariantMap,它本身只是一个别名,实际类型是HashMap