473,473 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

a weird memory problem

I ran into a weird memory problem.

my c++ code got a segmentation error at the execution. why I try to
debug it with gdb, I found out it was due to an earlier memory problem.
I then used both valgrind and efence tools, both tell me that an early
'new' operation failed.

But I have a try{}catch(std:bad_alloc){} block to catch bad memory
allocation exceptions. why it wasn't caught?

By the way, I have more than enough momory available for the code, why
i still get a bad memory allocation error?

thanks

Oct 19 '05 #1
11 3893
<ne********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I ran into a weird memory problem.

my c++ code got a segmentation error at the execution. why I try to
debug it with gdb, I found out it was due to an earlier memory problem.
I then used both valgrind and efence tools, both tell me that an early
'new' operation failed.

But I have a try{}catch(std:bad_alloc){} block to catch bad memory
allocation exceptions. why it wasn't caught?

By the way, I have more than enough momory available for the code, why
i still get a bad memory allocation error?


Bug on line 42.

-Mike
Oct 19 '05 #2
can you explain it in more detail?
thanks

Oct 20 '05 #3
ne********@gmail.com wrote:
can you explain it in more detail?
thanks

On the internet, people with small pipes frequently resort to a
highly-compressed form of communication, in order to save time and money
on uploading their replies. "Bug on line 42." decompresses to "You have
described how woeful your problem is in great detail, and your sorrows
are indeed sorrowful, but you have not adequately /described/ your
problem, perhaps by posting reasonably sized snippets of the code which
is causing you issues. Perhaps if you were to describe your code and
your problem more thoroughly, we might help you, but until then we can
only speculate wildly and fruitlessly."

Obviously, "Bug on line 42." is much more concise.
Oct 20 '05 #4
:) thanks

here is my problem:

I have 2 classses, node and edge. I construt a graph by constructing
one node or one edge at a time.
I have more than enough memory available.

the code works fine. But when I try to use valgrind to track memory
leak, it gave me a error "can't allocate memory" when the code created
half of the nodes and edges. Same thing happened when I link my code
with efence library.

In my code, I have try{}catch(){} block to test bad allocation. So it
seems without efence wrapper or valgrind, the allocation is fine, and
with them, I got a bad allocation error, and the error was not caught
by my code.

thanks

Oct 20 '05 #5
ne********@gmail.com wrote:
can you explain it in more detail?
thanks


Explain what?

When you reply to a post, please quote the relevant parts.
Best

Kai-Uwe Bux
Oct 20 '05 #6

<ne********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
:) thanks

here is my problem:

I have 2 classses, node and edge. I construt a graph by constructing
one node or one edge at a time.
I have more than enough memory available.

the code works fine. But when I try to use valgrind to track memory
leak, it gave me a error "can't allocate memory" when the code created
half of the nodes and edges. Same thing happened when I link my code
with efence library.

In my code, I have try{}catch(){} block to test bad allocation. So it
seems without efence wrapper or valgrind, the allocation is fine, and
with them, I got a bad allocation error, and the error was not caught
by my code.


Please read Jack's reply again, this time carefully.

-Mike
Oct 20 '05 #7
ne********@gmail.com wrote:
:) thanks

here is my problem:

I have 2 classses, node and edge. I construt a graph by constructing
one node or one edge at a time.
I have more than enough memory available.

the code works fine. But when I try to use valgrind to track memory
leak, it gave me a error "can't allocate memory" when the code created
half of the nodes and edges. Same thing happened when I link my code
with efence library.

In my code, I have try{}catch(){} block to test bad allocation. So it
seems without efence wrapper or valgrind, the allocation is fine, and
with them, I got a bad allocation error, and the error was not caught
by my code.


From this description, it is impossible to say anthing meaningful about the
problem. It could be a bug in valgrind or efence. It could be a bug in your
code. Without seeing what causes the problem, we cannot help you.

Hint: you may want to post some relevant code.
Best

Kai-Uwe Bux

Oct 20 '05 #8
ne********@gmail.com wrote:

I ran into a weird memory problem.

my c++ code got a segmentation error at the execution. why I try to
debug it with gdb, I found out it was due to an earlier memory problem.
I then used both valgrind and efence tools, both tell me that an early
'new' operation failed.

But I have a try{}catch(std:bad_alloc){} block to catch bad memory
allocation exceptions. why it wasn't caught?


It may be, that your real bug happend way before that bad allocation.
Eg. You overflowed an array and thereby destroyed the bookkeeping data
structure of the memory allocator. Or you destryoed the return value
stack (if your system uses a stack). Things like that.

--
Karl Heinz Buchegger
kb******@gascad.at
Oct 20 '05 #9
You mention that you have enough memory to run all three apps at once.
It might be the case that the memory itself is at fault. Problem memory
sticks seem to be commonplace these days. Try testing your RAM:
http://www.memtest86.com/#download0

Oct 20 '05 #10
ne********@gmail.com wrote:
:) thanks

here is my problem:

I have 2 classses, node and edge. I construt a graph by constructing
one node or one edge at a time.
I have more than enough memory available.

the code works fine. But when I try to use valgrind to track memory
leak, it gave me a error "can't allocate memory" when the code created
half of the nodes and edges. Same thing happened when I link my code
with efence library.

In my code, I have try{}catch(){} block to test bad allocation. So it
seems without efence wrapper or valgrind, the allocation is fine, and
with them, I got a bad allocation error, and the error was not caught
by my code.
It likely that an even earlier bug in your code caused the problem. As
youve already found out bugs often manifest themselves much later than
the actual problem.

Once a bug has corrupted your heap all bets are off and you start to get
wierd problems like the above. If would go with the version that is
crashing and start to remove features from your code. At some point you
will find that it stops crashing, at that point the last thing you
removed will likely be the cause of the problem.

Hopefully you will take a lesson from this painful process. Don't mess
with pointers. Use smart pointers if possible.

thanks


john
Oct 20 '05 #11
ne********@gmail.com wrote:
can you explain it in more detail?
thanks


I think what he was trying to say is that we can't help you unless you
post some code ;-)
Oct 20 '05 #12

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

Similar topics

1
by: Pelle | last post by:
Hello all, I have to admit, that the idea that occurred to me recently is weird. It was somehow inspired by the huge response on the "delete operator" thread, but goes into a somewhat different...
7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
10
by: Chris Mantoulidis | last post by:
I see some really weird output from this program (compiled with GCC 3.3.2 under Linux). #include <iostream> using namespace std; int main() { char *s; s = "test1"; cout << "s = " << s << "...
2
by: Christian Kreimer | last post by:
Hi I created an C# windows forms application that holds a user control. The user control itself is an editor for geographical information systems and is based on an ActiveX Library for providing...
4
by: Bo Peng | last post by:
Dear list, I spent the last 12 hours in catching this bug (?) and what I found out is very difficult to explain: Basically, I need to call a user-provided function many times, with a tuple as...
2
by: ian | last post by:
Hi, I've got the weirdest garbage collection problem - I'd appreciate any advice you've got. 1. A class 'X' in a system I'm working on contains a reference to an XmlDocument, populated via...
18
by: atv | last post by:
at least to me it is. I can't figure out for the life what it is i'm doing wrong here. i have a function called assign_coordinate. usually, i pass a malloced pointer to it, then individual...
6
by: itsolution | last post by:
Hi folks, Could you shed some light on this issue? my program is running on Freebsd as a daemon. When user sends a request, it forks itself and lets its child process handles the request....
14
by: leptone | last post by:
Dear all, I am programming a PLC with an 80188 processor, hence I am using an old version of Borland C++ (3.10). While doing the job, I've encountered strange behaviours and I've isolated the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
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...
0
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...
0
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 ...
0
bsmnconsultancy
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...

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.