This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: String and std::string


<snip>

> I don't care whether you use std::string, or
> String++ for any new code,
> as long as:
> 1) You don't leak memory (std::string will leak if
> you use c_str())
> IIRC.

I've been unable to confirm this. I tried the attached
program (compiled with gcc -lstdc++ stringleak.cpp)
and got the following results from top: 

PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM  
  648 alex      14   0   556  556   416 R    56.2  0.2
  

TIME COMMAND
3:02 a.out

Am I correct in concluding that std::string::c_str()
does not leak? I'm interested as I use c_str() a fair
amount for interfacing C++ with C (I believe that was
what it was designed for, but I'm only guessing).

Regards,
Alex

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
#include <string>
#include <iostream>

int main()
{
	std::string bleg("bleg");
	while (true)
	{
		std::cout << bleg.c_str();
	}
	
	return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]