It’s not a big deal due to move semantics, perfect forwarding, copy elision and small string optimization.
Really? For example, in this common (I think) code there’s 1000 unnecessary memory allocations:
for(int index = 0; index < 1000; index++)
Sprite* sprite = Sprite::createWithSpriteFrameName("whatever");
Your class provides yet another layer of indirection and makes it harder for the optimizer to inline calls, you have not implemented move-friendly methods.
I think the example class is too short and simple to have problems with inlining.
What I posted is a quick example to get the idea, so some move-friendly methods would be great.
Anyway, the example class already has move semantics, because move constructor and assignment operator is added automatically:
And the memory usage is going to increase.
The size of and empty std::string and a const char* pointer is going to be lower than the size of a non-empty std::string, and memory fragmentation is avoided until it’s necessary.
The point is, how often cocos2d-x classes manipulates the text stored in a std::string?
I think if the answer is not much, a solution like my example class is going to perform better.