Hi
I wrote a C++Builder program that throws/catch many exceptions
(let's say 1.000.000/ hours). The problem is that I think that is a
bug in the Borland C++Builder exception handling mechanism.
If I catch an exception with catch(...) the memory is never freed! so
my computer can quickly get memory-exhausted.
Here is the code that generates the problem. In VC++ I don't have this
problem. Neither Delphi. I've managed to solve it somehow (as shown in
the second part), but I think that this is not a solution, mainly
because the program is slower in the second case and I'm not sure that
I catch all exceptions.
Does anybody else has another solution to my problem?
thanks,
mihai
#include <vcl.h>
#pragma hdrstop
//-------------------------------------------------------------------
--------
#pragma argsused
int main(int argc, char* argv[])
{
int a = 4;
int b = 0;
int c;
// the case where the memory is not freed
for (int i = 0; i < 1000000; i++)
try{
c = a/b;
}
catch(...){ // with this I catch all exceptions
c = 1;
}
/*
// the case when the memory is freed
for (int i = 0; i < 1000000; i++)
try{
c = a/b;
}
catch(Exception &e){
c = 1;
e.Free(); //Borland says "never call Free()"!
}
*/
return 0;
}
//-------------------------------------------------------------------
-------- 5 6162
"Mihai Oltean" <mi*********@ya hoo.com> wrote in message
news:4e******** *************** ***@posting.goo gle.com... Hi
I wrote a C++Builder program that throws/catch many exceptions (let's say 1.000.000/ hours). The problem is that I think that is a bug in the Borland C++Builder exception handling mechanism.
If I catch an exception with catch(...) the memory is never freed! so my computer can quickly get memory-exhausted.
Here is the code that generates the problem. In VC++ I don't have this problem. Neither Delphi. I've managed to solve it somehow (as shown in the second part), but I think that this is not a solution, mainly because the program is slower in the second case and I'm not sure that I catch all exceptions.
Does anybody else has another solution to my problem?
thanks, mihai
#include <vcl.h> #pragma hdrstop
//------------------------------------------------------------------- -------- #pragma argsused int main(int argc, char* argv[]) { int a = 4; int b = 0; int c;
// the case where the memory is not freed for (int i = 0; i < 1000000; i++) try{ c = a/b; } catch(...){ // with this I catch all exceptions c = 1; }
/* // the case when the memory is freed for (int i = 0; i < 1000000; i++) try{ c = a/b; } catch(Exception &e){ c = 1; e.Free(); //Borland says "never call Free()"! } */ return 0; }
I think you are not going to get an answer to this problem unless you post
some compilable code.
What is <vcl.h>? It's not part of standard C++. What is Exception? Is it
defined in <vcl.h>? If these two are important to your problem, then you
should ask on a group where they are topical, presumably a Borland group.
Also you should be aware that division by zero does not cause an exception,
it causes undefined behaviour. So if in your real program you are doing a
divide by zero, then the Borland compiler can do what it likes and you have
no reason to complain. It's not a bug, its a feature of C++.
john
Mihai Oltean wrote: Hi
I wrote a C++Builder program that throws/catch many exceptions (let's say 1.000.000/ hours). The problem is that I think that is a bug in the Borland C++Builder exception handling mechanism.
If I catch an exception with catch(...) the memory is never freed! so my computer can quickly get memory-exhausted.
Here is the code that generates the problem. In VC++ I don't have this problem. Neither Delphi. I've managed to solve it somehow (as shown in the second part), but I think that this is not a solution, mainly because the program is slower in the second case and I'm not sure that I catch all exceptions.
Does anybody else has another solution to my problem?
thanks, mihai
#include <vcl.h>
This is a non-standard header.
#pragma hdrstop
//------------------------------------------------------------------- -------- #pragma argsused
These preprocessor directives are specific to a
particular implementation. Hence ignoring it.
int main(int argc, char* argv[]) {
We dont use either of them. So never mind to put them here.
int a = 4; int b = 0; int c;
// the case where the memory is not freed for (int i = 0; i < 1000000; i++)
Array indices would better be defined as size_t .
What about the opening brace to signify the beginning
of the block, belonging to this loop ?
try{ c = a/b;
This would result in a divide-by-zero error.
I am not really sure if dividing by zero, results in an
error or an exception.
<-- Code Begins -- >
#include <cstdlib> //EXIT_SUCCESS , system
#include <iostream> //cout, endl
#include <stdexcept> //logic_error
int mydiv(int num, int den);
int main() {
int a = 4;
int b = 0;
int c;
// the case where the memory is not freed
for (size_t i = 0; i < 1000000; i++) {
try {
// c = a/b; // Let me replace it with my custom function
c = mydiv(a, b);
} catch(...){ // with this I catch all exceptions
c = 1;
}
}
std::cout << "Out of the loop " << std::endl;
system("pause") ;
return EXIT_SUCCESS;
}
int mydiv(int num, int den) {
if (!den) {
throw std::logic_erro r("Divide by zero");
} else {
return ( num / den ) ;
// Crude integer division that is.
}
}
<-- Code Ends -->
This code ran successfully , in my implementation.
The exception handlers were invoked 1000000 times ( the
same upper bound specified for the loop).
<OT>
I run MinGW.
gcc (GCC) 3.4.2 (mingw-special)
</OT>
--
Karthik.
On 6 Oct 2004 23:18:20 -0700, mi*********@yah oo.com (Mihai Oltean)
wrote: If I catch an exception with catch(...) the memory is never freed! so my computer can quickly get memory-exhausted.
This is definitely off-topic in comp.lang.c++, but I will give you the
answer because it is short, and you may have trouble finding it
elsewhere.
This is a known issue with Borland. The solution is: Don't ever use
catch(...). Specify the type of exception, e.g.:
catch(const std::exception &e)
// any of the STL containers might throw this
// or an exception derived from std::exception
or for SEH-type exceptions, which are wrapped by the VCL as Exception:
catch(Exception &e)
// note that you cannot, for some reason,
// catch a const Exception & because of the way
// Borland implements it.
HTH
--
Bob Hairgrove No**********@Ho me.com
Thanks Bob,
The problem if I use:
catch(Exception &e)
is that I have to call e.Free() at the end of catch block. Otherwise
the memory will not be freed. And Borland does not say anything about
that. But if I throw the exception myself and then try to catch it I
don't have to use e.Free() because I get an error!
regards,
mihai
Bob Hairgrove <in*****@bigfoo t.com> wrote in message news:<ph******* *************** **********@4ax. com>... On 6 Oct 2004 23:18:20 -0700, mi*********@yah oo.com (Mihai Oltean) wrote:
If I catch an exception with catch(...) the memory is never freed! so my computer can quickly get memory-exhausted.
This is definitely off-topic in comp.lang.c++, but I will give you the answer because it is short, and you may have trouble finding it elsewhere.
This is a known issue with Borland. The solution is: Don't ever use catch(...). Specify the type of exception, e.g.:
catch(const std::exception &e) // any of the STL containers might throw this // or an exception derived from std::exception
or for SEH-type exceptions, which are wrapped by the VCL as Exception:
catch(Exception &e) // note that you cannot, for some reason, // catch a const Exception & because of the way // Borland implements it.
HTH
I'm extremely new here and not done much to speak of with windows C++
but seems you speak of the same Borland Builder that I'm playing with.
I've just finished the Tutorial on making their small Editor. Yes,
finished and flunked it because they give a bad line in the Save
Command. I've dropped them a line but......???? Did you find the
answer to this one?
I've done a lot of work with VB so have some experience with that and
C and such for years off and on plus a lot of C++ for dos which simply
doens't hit it any longer with XP and on.
Verne
On 7 Oct 2004 23:55:02 -0700, mi*********@yah oo.com (Mihai Oltean)
wrote: Thanks Bob,
The problem if I use:
catch(Exceptio n &e)
is that I have to call e.Free() at the end of catch block. Otherwise the memory will not be freed. And Borland does not say anything about that. But if I throw the exception myself and then try to catch it I don't have to use e.Free() because I get an error!
regards, mihai
Bob Hairgrove <in*****@bigfoo t.com> wrote in message news:<ph******* *************** **********@4ax. com>... On 6 Oct 2004 23:18:20 -0700, mi*********@yah oo.com (Mihai Oltean) wrote:
>If I catch an exception with catch(...) the memory is never freed! so >my computer can quickly get memory-exhausted.
This is definitely off-topic in comp.lang.c++, but I will give you the answer because it is short, and you may have trouble finding it elsewhere.
This is a known issue with Borland. The solution is: Don't ever use catch(...). Specify the type of exception, e.g.:
catch(const std::exception &e) // any of the STL containers might throw this // or an exception derived from std::exception
or for SEH-type exceptions, which are wrapped by the VCL as Exception:
catch(Exception &e) // note that you cannot, for some reason, // catch a const Exception & because of the way // Borland implements it.
HTH This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anand K Rayudu |
last post by:
Hi All,
I am new to python & want to build some GUI dialogs.
Can some one please suggest some document reference.
I am hoping that standard python install will have some GUI development
modules & GUI builder in built.
I have python 2.3.3.
Can some one please suggest
|
by: Xproblem |
last post by:
FTP Client Engine for C/C++ 2.4 Screenshot - Soft.comFTP Client Engine
for C/C++ 2.4. ... System Requirements: Windows C/C++ compiler -
Microsoft operating system: Windows 95, Windows 98, Windows ME, ...
www.soft30.com/screen-70-11625.htm - 31k - Cached - Similar pages
C++ Server Pages 1.6 - Soft.comC++ Server Pages (CSP) allows developers
to build Dynamic Web Pages and Web ... Existing C++ projects can be
ported to the Web by simply...
|
by: Mike Turco |
last post by:
I like using the expression builder for a lot of different things but it
isn't always available when I want to use it, for example in the code
window, or in all of the control properties. I am usually stuck having to go
into the database window, creating a new query, etc., and then
right-clicking in a field and selecting build.
Is there a shortcut key, a way to add a button to an Access toolbar, or
something like that so I can use to...
|
by: FluffyCat |
last post by:
Last fall I started a series of design pattern examples using PHP5. I
think the last pattern I did was the Singleton in January. Getting
back to it here is my first cut at the Builder pattern.
http://www.fluffycat.com/PHP-Design-Patterns-Builder/
In the builder pattern a director and builder work togther to build an
object. The director controls the building and specifies any
variations that can be done with the object. The builder...
|
by: sicapitan |
last post by:
FYI,
with something like this:
hotelement = "hotelement"+hotcount;
hotspot = Builder.node('div', { id:'hotspot'+hotcount,
className:'hotspot', style:''+divstyle }, )
]);
| |
by: simonZ |
last post by:
I have array variable transfer: String transfer which has some data
Than I would like to convert this data into string:
Which way is more efficient:
StringBuilder rezult=new StringBuilder();
for (int i = 0; i < transfer.Length; i++)
{
|
by: EddieTH |
last post by:
Hello everyone, I am new to this forum so I'll give my greetings to everyone!
I am using oracle forms builder and reports builder for 1 year now and I have a problem I cannot seem to be able to solve!
I 've used report builder yesterday and worked fine, this morning when I tried to open an rdf using reports builder it would not open at all.
The same thing happened few days ago with forms builder.
Does anyone knows what's wrong???
ps....
|
by: JosAH |
last post by:
Greetings,
Introduction
Before we start designing and implementing our text builder class(es), I'd like
to mention a reply by Prometheuzz: he had a Dutch version of the entire bible
available, including those apocryphical books. I downloaded the entire shebang,
hacked my King James text processor a bit and now I have two bibles available:
the English 'King James' version and the Dutch 'Staten Vertaling' version.
|
by: xarzu |
last post by:
Platform Builder is a tool for building a Windows CE Operating system on your computer and then loading it on a Windows CE device.
All this is done through Platform Builder. And I do it all through the Microsoft Visual Stuido Development Environment (IDE).
I want to automate the process of using the Platform Builder. So far, I only know how to use the Platform Builder through the IDE. I want to use the Platform Builder through another...
|
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: 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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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...
| |