I am working on a c++ module, where large amount of data needs to be
written to a stream and str() method is been used to assign the value
of this to the char*. This produces the intended result. But when i run
purify on it i get the following results.
[W] MLK: Memory leak of 8656 bytes from 9 blocks allocated in
strstreambuf::d oallocate(void) [Builder.exe]
Distribution of leaked blocks
987 bytes from 1 block of 987 bytes (0x03977ea8)
980 bytes from 1 block of 980 bytes (0x038ff010)
976 bytes from 1 block of 976 bytes (0x03974cf8)
969 bytes from 1 block of 969 bytes (0x03969290)
962 bytes from 1 block of 962 bytes (0x03967a00)
960 bytes from 1 block of 960 bytes (0x03965d78)
958 bytes from 1 block of 958 bytes (0x038fe388)
957 bytes from 1 block of 957 bytes (0x003961f8)
907 bytes from 1 block of 907 bytes (0x041080b0)
Allocation location
new(UINT,int,ch ar const*,int) [dbgnew.cpp:46]
strstreambuf::d oallocate(void) [_strstre.cpp:20 1]
strstreambuf::o verflow(int) [_strstre.cpp:25 6]
streambuf::xspu tn(char const*,int) [streamb.cpp:182]
streambuf::sput n(char const*,int) [.\.\streamb.h:1 87]
ostream::writep ad(char const*,char const*)
[ostream.cpp:166]
ostream::<<(cha r const*) [ostream.cpp:61]
writeInvisibleO bject(char *,char *,char *,char const*)
[E:\Builder\src\ main.cpp:2499]
This happens at the line where the char* is been assigned to the
strstream variable.
strstream strmvar;
strmvar << dataChar;
char* datadetail = strmvar.str();
delete datadetail;
Initially i assumed the reason to be writing a char* to the strstream
variable. But the error occured when i tried with int even. The purify
results indicate that it if beacuse of a overflow to the strstream var.
As for as my understanding the new memory that is been allocated was
never deleted. Since the program involves a huge amount of data this
could occur. Is the overflow the cause for the leak? Is there a way to
get rid of this leak? I definitely need to remove this as we are
running the code in batch mode for a set of input files. and this may
affect the performance of the application when run continously and may
lead to out of memory error even.
Can someone help me? 5 3741 ni******@gmail. com wrote:
I am working on a c++ module, where large amount of data needs to be
written to a stream and str() method is been used to assign the value
of this to the char*. This produces the intended result. But when i run
purify on it i get the following results.
[W] MLK: Memory leak of 8656 bytes from 9 blocks allocated in
strstreambuf::d oallocate(void) [Builder.exe]
Distribution of leaked blocks
987 bytes from 1 block of 987 bytes (0x03977ea8)
980 bytes from 1 block of 980 bytes (0x038ff010)
976 bytes from 1 block of 976 bytes (0x03974cf8)
969 bytes from 1 block of 969 bytes (0x03969290)
962 bytes from 1 block of 962 bytes (0x03967a00)
960 bytes from 1 block of 960 bytes (0x03965d78)
958 bytes from 1 block of 958 bytes (0x038fe388)
957 bytes from 1 block of 957 bytes (0x003961f8)
907 bytes from 1 block of 907 bytes (0x041080b0)
Allocation location
new(UINT,int,ch ar const*,int) [dbgnew.cpp:46]
strstreambuf::d oallocate(void) [_strstre.cpp:20 1]
strstreambuf::o verflow(int) [_strstre.cpp:25 6]
streambuf::xspu tn(char const*,int) [streamb.cpp:182]
streambuf::sput n(char const*,int) [.\.\streamb.h:1 87]
ostream::writep ad(char const*,char const*)
[ostream.cpp:166]
ostream::<<(cha r const*) [ostream.cpp:61]
writeInvisibleO bject(char *,char *,char *,char const*)
[E:\Builder\src\ main.cpp:2499]
This happens at the line where the char* is been assigned to the
strstream variable.
strstream strmvar;
strmvar << dataChar;
char* datadetail = strmvar.str();
delete datadetail;
Initially i assumed the reason to be writing a char* to the strstream
variable. But the error occured when i tried with int even. The purify
results indicate that it if beacuse of a overflow to the strstream var.
As for as my understanding the new memory that is been allocated was
never deleted. Since the program involves a huge amount of data this
could occur. Is the overflow the cause for the leak? Is there a way to
get rid of this leak? I definitely need to remove this as we are
running the code in batch mode for a set of input files. and this may
affect the performance of the application when run continously and may
lead to out of memory error even.
Can someone help me?
First, you should use std::stringstre ams instead of std::strstreams if
at all possible. The latter have been deprecated.
Second, I think your problem might be that you forgot to terminate the
strstream with std::ends:
strstream strmvar;
strmvar << dataChar << ends;
Cheers! --M ni******@gmail. com wrote:
>
strstream strmvar;
strmvar << dataChar;
char* datadetail = strmvar.str();
delete datadetail;
delete [] datadetail;
I'm surprised Putrify doesn't give you an explicit error on this
one.
Ron Natalie wrote:
ni******@gmail. com wrote:
strstream strmvar;
strmvar << dataChar;
char* datadetail = strmvar.str();
delete datadetail;
delete [] datadetail;
I'm surprised Putrify doesn't give you an explicit error on this
one.
Thanks. Since i am working on Windows probably purify didn't throw an
error on this.
I solved the problem that i had stated. That was because of the failure
to use freeze method. Once i unfreezed the buffer the destructor itself
took care of the deallocation of the strstream variable.
strmvar.rdbuf()->freeze(0);
made me fix the problem. Is this going to be a problem when I port the
application to UNIX? Do I need to make any changes to make it work?
mlimber wrote:
ni******@gmail. com wrote:
I am working on a c++ module, where large amount of data needs to be
written to a stream and str() method is been used to assign the value
of this to the char*. This produces the intended result. But when i run
purify on it i get the following results.
[W] MLK: Memory leak of 8656 bytes from 9 blocks allocated in
strstreambuf::d oallocate(void) [Builder.exe]
Distribution of leaked blocks
987 bytes from 1 block of 987 bytes (0x03977ea8)
980 bytes from 1 block of 980 bytes (0x038ff010)
976 bytes from 1 block of 976 bytes (0x03974cf8)
969 bytes from 1 block of 969 bytes (0x03969290)
962 bytes from 1 block of 962 bytes (0x03967a00)
960 bytes from 1 block of 960 bytes (0x03965d78)
958 bytes from 1 block of 958 bytes (0x038fe388)
957 bytes from 1 block of 957 bytes (0x003961f8)
907 bytes from 1 block of 907 bytes (0x041080b0)
Allocation location
new(UINT,int,ch ar const*,int) [dbgnew.cpp:46]
strstreambuf::d oallocate(void) [_strstre.cpp:20 1]
strstreambuf::o verflow(int) [_strstre.cpp:25 6]
streambuf::xspu tn(char const*,int) [streamb.cpp:182]
streambuf::sput n(char const*,int) [.\.\streamb.h:1 87]
ostream::writep ad(char const*,char const*)
[ostream.cpp:166]
ostream::<<(cha r const*) [ostream.cpp:61]
writeInvisibleO bject(char *,char *,char *,char const*)
[E:\Builder\src\ main.cpp:2499]
This happens at the line where the char* is been assigned to the
strstream variable.
strstream strmvar;
strmvar << dataChar;
char* datadetail = strmvar.str();
delete datadetail;
Initially i assumed the reason to be writing a char* to the strstream
variable. But the error occured when i tried with int even. The purify
results indicate that it if beacuse of a overflow to the strstream var.
As for as my understanding the new memory that is been allocated was
never deleted. Since the program involves a huge amount of data this
could occur. Is the overflow the cause for the leak? Is there a way to
get rid of this leak? I definitely need to remove this as we are
running the code in batch mode for a set of input files. and this may
affect the performance of the application when run continously and may
lead to out of memory error even.
Can someone help me?
First, you should use std::stringstre ams instead of std::strstreams if
at all possible. The latter have been deprecated.
Second, I think your problem might be that you forgot to terminate the
strstream with std::ends:
strstream strmvar;
strmvar << dataChar << ends;
Cheers! --M
Once you are done with object of strstream that's strmvar call
freeze(true) on strmvar.
strmvar.freeze( true);
I too had the same problem earlier.
This worked fine.
But change the deprecated strstream to stringstream.
Regards
Sunil ni******@gmail. com wrote:
Ron Natalie wrote:
ni******@gmail. com wrote:
>
strstream strmvar;
strmvar << dataChar;
>
char* datadetail = strmvar.str();
delete datadetail;
delete [] datadetail;
I'm surprised Putrify doesn't give you an explicit error on this
one.
Thanks. Since i am working on Windows probably purify didn't throw an
error on this.
I solved the problem that i had stated. That was because of the failure
to use freeze method. Once i unfreezed the buffer the destructor itself
took care of the deallocation of the strstream variable.
strmvar.rdbuf()->freeze(0);
made me fix the problem. Is this going to be a problem when I port the
application to UNIX? Do I need to make any changes to make it work?
As long as you are able to change things, switch to std::stringstre ams
without delay, and your problems will all magically go away! (Ok,
that's an exaggeration, but it will likely help since memory management
will be much simpler.)
Cheers! --M This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: vishnu mahendra |
last post by:
hello to all,
#include<iostream.h>
#include<conio.h>
#include <strstream.h>
void main()
{
clrscr();
strstream str;
char *a = new char;
int i;
|
by: Aaron Gray |
last post by:
Hi,
I have an application that uses 'strstream' in just under half its .cc
files, about 10 files.
What is the replacement for 'strstream' ?
What are my options for replacing it ?
Many thanks in advance,
|
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 ?
In nut shell, what is/are the realtion/s between the Memory Leak and
Memory Corruption.
Juts Theoritical Assumtion below:
|
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 easier to reproduce (e.g.: remote machine
not available). After about 1 day, I get a usage of 300MB of memory.
I have used .NET Memory Profiler tool to try to see where the leak is
located. For all the leaky instances, I can see the following (I...
|
by: Don Nell |
last post by:
Hello
Why is there a memory leak when this code is executed.
for(;;)
{
ManagementScope scope = new ManagementScope();
scope.Options.Username="username";
scope.Options.Password="password";
scope.Path.Path=@"\\pc\root\cimv2";
| |
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex matches are called
within a loop (like if or for). E.g.
for(int i = 0; i < 10; i++)
{
Regex r = new Regex();
|
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
|
by: Jim Land |
last post by:
Jack Slocum claims here
http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript-
memory-leaks/
that "almost every site you visit that uses JavaScript is leaking memory".
Anybody know anything about this?
Does *Javascript* leak memeory, or
does the *browser* leak memory?
|
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 memory leak someplace. I can not detect the memory
leak by running several reports by hand, but when I run tha app as a
servrice and process few hundred reports there is significant memory leak.
The application can consume over 1GB of memory where it...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |