Strings in the Torque Engine
by Ingo Seidel · in Torque Game Engine · 06/07/2006 (2:30 am) · 6 replies
Hello!
I am currently developing a Torque project, where I have to write my own classes in C++ that use strings to hold some data. Normally in C++ I would use the std::string implementation of the standard library. Since Torque does not work with this natively I would have to apply a patch to use std::string. The other way, where I would need no patching, is to use char, but then I have to do all the memory management on my own. A third possibility would be to use some other string implementation (as far as I have seen Torque has no built in string class).
Now I wanted to know which method you should use (or you are using) when programming Torque:
* std::string, with patch
* ordinary char with own memory management
* other string implementation
thanks
I am currently developing a Torque project, where I have to write my own classes in C++ that use strings to hold some data. Normally in C++ I would use the std::string implementation of the standard library. Since Torque does not work with this natively I would have to apply a patch to use std::string. The other way, where I would need no patching, is to use char, but then I have to do all the memory management on my own. A third possibility would be to use some other string implementation (as far as I have seen Torque has no built in string class).
Now I wanted to know which method you should use (or you are using) when programming Torque:
* std::string, with patch
* ordinary char with own memory management
* other string implementation
thanks
#2
06/07/2006 (7:54 am)
Yes you can use std::string in Torque but you may need an additional patch to get it work (as in my case). See stl_fix. Using this patch implies that you can't simply switch to new Torque versions (as you will have to apply the patch again first) and that the patch may not work on all platforms (which can be a problem if you develop for multiple platforms). Therefore I was unsure weather it is a good idea to apply the patch and wanted to know how other people deal with this problem.
#3
06/07/2006 (8:09 am)
If you just need to hold string data, C strings are fairly easy to use.
#4
06/07/2006 (12:49 pm)
I dont know the size of my strings in advance and I need to append strings where again I dont know the size of either string in advance. If I do this with C strings I will always have to check if there is enough memory such that a new string fits in. If there is not enough memory I need to reallocate my string. The same again if I want to append strings. If I do this in my code this becomes very tedious. Do you really use C strings for things like that? I bet there are a lot of pitfalls and segmentation faults you can run into.
#6
06/07/2006 (7:41 pm)
Ummm, why not use a method similar to the way strings are passed to and from the script portion of Torque? That way if you ever need to link it to script it is not a hassel to covert.
Torque Owner Martin de Richelieu