Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » About string, String and const char *
About string, String and const char * [message #7413] Thu, 28 December 2006 10:16 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, I have just down an interesting investigation (because of some discussion thread in comp.alt.c++.moderated) which also nicely explains why in U++ we are using "const char*" instead of String so often.

#include <string>

void foo(const std::string& x);
void foo2(const char *s);

void Test1()
{
	foo("just a test");
}

void Test2()
{
	foo2("just a test");
}


Now Test1 has 115 bytes, Test2 12 bytes... (and it is similar for String too).

Mirek
Re: About string, String and const char * [message #7414 is a reply to message #7413] Thu, 28 December 2006 10:40 Go to previous messageGo to next message
fallingdutch is currently offline  fallingdutch
Messages: 258
Registered: July 2006
Experienced Member
Ultimate++ rocks Cool

Bas
Re: About string, String and const char * [message #7418 is a reply to message #7413] Thu, 28 December 2006 11:50 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

luzr wrote on Thu, 28 December 2006 04:16

Well, I have just down an interesting investigation (because of some discussion thread in comp.alt.c++.moderated) which also nicely explains why in U++ we are using "const char*" instead of String so often.

#include <string>

void foo(const std::string& x);
void foo2(const char *s);

void Test1()
{
	foo("just a test");
}

void Test2()
{
	foo2("just a test");
}


Now Test1 has 115 bytes, Test2 12 bytes... (and it is similar for String too).

Mirek


Quite huge difference. If Test1 is translated to sth like this:

void Test1()
{
   const std::string x("just a test");
   foo(x);
}

..it is still interesting that creating string object needs 103 bytes more.
Re: About string, String and const char * [message #7421 is a reply to message #7418] Thu, 28 December 2006 12:01 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Quote:


void Test1()
{
   const std::string x("just a test");
   foo(x);
}

..it is still interesting that creating string object needs 103 bytes more.


It is because exception handling...

Mirek
Previous Topic: Build UPP modules into DLL with import library
Next Topic: Twain - support for scanners - needed
Goto Forum:
  


Current Time: Fri Apr 26 00:40:58 CEST 2024

Total time taken to generate the page: 0.04204 seconds