473,395 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ostrstream and memory leak

tcl
Questions on ostrstream.
#1) do I have a memory leak as the control exits the scope
{
ostrstream os;
os << "hello world" << endl << ends;
}
#2) if there's no memory leak in #1, is there a leak here:
{
ostrstream os;
os << "hello world" << endl << ends;
cout << os.str();
}
#3) if there's a memory leak in either #1 or #2, would adding
either of the following statements right before exiting
the scope fix it? if not, how to fix it?
os.freeze(0);
delete [] os;

Thanks,
tcl

Oct 4 '05 #1
1 2782
tcl wrote:
Questions on ostrstream.
#1) do I have a memory leak as the control exits the scope
{
ostrstream os;
os << "hello world" << endl << ends;
}
No.

#2) if there's no memory leak in #1, is there a leak here:
{
ostrstream os;
os << "hello world" << endl << ends;
cout << os.str();
}
Unfortunately yes because ostrstream is very badly designed.


#3) if there's a memory leak in either #1 or #2, would adding
either of the following statements right before exiting
the scope fix it? if not, how to fix it?
os.freeze(0);
I think the above is OK but consult your documentation.
delete [] os;


The above is an error, probably shouldn't even compile.

Better still use ostringstream, then you don't need to worry about any
of this nonsense.

john
Oct 4 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Charles Prince | last post by:
How do I reuse a ostrstream? So far I have replaced all code that does this "delete <ostrstream>.str()" with "<ostrstream>.freeze(0)"
1
by: becte | last post by:
I encountered the following code similar to this // some header files static char* func(int i) { ostrstream out; if (i==1) out << "ABCDE"; else if (i==2) out << "123"; else cout << "";
2
by: b83503104 | last post by:
Hi, An old code is using stuff like #include <strstream.h> ostrstream *m_actionStream; and the compiler complained syntax error before `*' token I followed some previous posts and tried...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
6
by: Eric Chomko | last post by:
I inherited a task which uses a lot of 'ostrstream' in the code. The port is from an SGI box to Sun which is using GNU C++ (g++ version 3.4.2). When trying to compile I get several errors all...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
1
by: GeeBee | last post by:
1) I’m using Borland C++ Builder 1.0 (a very old (but still good) version). 2) I have an application EXE calling a DLL. 3) A function in the DLL receives a parameter defined as "ostream &" , and...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.