Newby C++ vs. C question
Hi guys,
I am a newby in the C/C++ world, and I am beginning to work on a
rather simple TCP/IP proxy application which must be able to handle
large volume of data as quickly as possible.
Since this application has to process and distribute plain text around
the network, I am wondering if there are any peformance differences
between C++ std::string and C char[] in run time?
Which one would you suggest me to use for my particular task (TCP/IP
proxy which is distributing plain text around the nextwork that
is :-) )?
Thanks, Alex
p.s.: here're two examples that I found on the Internet for which I am
wondering if there are any performance differences between them:
==========================
C function returning a copy
==========================
char *fnConvert(int _ii)
{
char *str = malloc(10); /* Return 10 character string */
if(str == NULL)
fprintf(stderr,"Error: Memory allocation failed.\n");
sprintf(str, "%d", _ii);
return str;
}
==========================
C++ function returning a copy
==========================
string fnConvert(int _ii)
{
ostringstream ost;
ost << _ii;
return ost.str();
}