Jump to content

Strings


Josh
 Share

Recommended Posts

Here are my imperatives for strings:

 

1. Ability to add two strings, i.e. Print( a+", "+b )

 

2. Ability to insert objects into a map by string. If a mesh is loaded, I want to insert the mesh into a map and be able to retrieve it with the file path.

 

3. Maximum compatibility on all platforms.

 

 

The way I see it, I have three options:

 

1. Use std:strings.

 

2. Add operators to const char* (if it's possible)

 

3. Make my own string class.

 

 

Questions:

 

1. Is std:string safe to use? Will it work on PS3, Android, etc?

 

2. Is there a way to automatically convert a string I type into my own string object? i.e.:

String s = "Hello";

 

Thanks.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Use std::string always, don't even think about using anything else. It will work everywhere, even on my AIX system which is so backwards like an dinosaur (well it's actually so because IBM is a dinosaur) :blink:

 

You CAN use char* for extremely speed sensitive system functions, but for user code it's always string which you should use. In system programming you have to use pure C anyway, since every nanosecond of delay matters. That's why it's also good to mix C with C++ code for cases where you know exactly that it's an abstract code and does not fail with infinite amount of data.

 

A game engine is not system programming, so you can use C++ and STL freely.

 

Making an own String class will give you a slower string class, since STL has been insanely well optimized over years. Even a normal QuickSort routine is slower than STL's built-in sorting functions, because STL switches automatically between different sorting algorithms according to the data type and structure you want to sort.

It may also be that some C++ compilers are especially optimized to provide maximum performance with STL classes, so no custom classes can ever beat that.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Funnily enough, only a few days ago I found myself writing a soft of beginners guide to using Leadwerks in a C/C++ environment and one of the topics was strings. Even I was saying to use the std::string and I'm by no means an expert compared to the rest of the posters in this thread.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

boost::string is useful in some cases...

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

They need boost anyway, because LuaBind needs it. The Codewerks installer can have all libs it needs packaged with it, and then its up to the user if he wants to install them, or if he already has them installed.

 

That's how BlitzMax works too, it has all the libs it needs packaged with it.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

They need boost anyway, because LuaBind needs it. The Codewerks installer can have all libs it needs packaged with it, and then its up to the user if he wants to install them, or if he already has them installed.

 

That's how BlitzMax works too, it has all the libs it needs packaged with it.

Okidoki

AV MX Linux

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...