473,804 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception checking memory allocation. How?

It is common practice (I've heard) to always catch
allocation exceptions from "new". How is done in
practice? What would be a common procedure (path of
sequence) after such an event has occured? (For a
multi-million LOC, GUI based application).

It is also a common advice not to allocate objects
with "new" unless absolutely required. The alternative
is to keep objects on the stack, automatically allocated
and deallocated by scope control. Which mechanisms do
I use in order to prevent allocation errors (i.e. stack
overflow) in this case?

Thanks!
Jul 30 '05
16 2524
Jacob wrote:
somehow. Following my company guidelines inter-library exception
throw/catch is not an option, so I need to use other mechanisms.


But wasn't you who were deciding the guidelines?

--
Salu2
Jul 30 '05 #11
Julián Albo wrote:
somehow. Following my company guidelines inter-library exception
throw/catch is not an option, so I need to use other mechanisms.

But wasn't you who were deciding the guidelines?


Yes. And according to C++ best practices, inter-library
exceptions is not adviced.
Jul 30 '05 #12
Jacob wrote:
somehow. Following my company guidelines inter-library exception
throw/catch is not an option, so I need to use other mechanisms.

But wasn't you who were deciding the guidelines?

Yes. And according to C++ best practices, inter-library
exceptions is not adviced.


Is "C++ best practices" the name of your company, then?

--
Salu2
Jul 30 '05 #13
Jacob sade:
You just encouter a memory allocation failure, but the program
should be able to continue.


What if the memory allocation failure isn't just a single event,
but a complete process memory failure, what are your options then?
Can your application react and save necessary, perhaps crucial, data
without the need for more heap memory?

My experience is that most programs just crash with a curious message,
sometimes generated from the dark depths of the code structure,
hence my first answer. Memory allocation control is a rare thing.

Tobias
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
Jul 30 '05 #14
Tobias Blomkvist wrote:
My experience is that most programs just crash with a curious message,
sometimes generated from the dark depths of the code structure,


Commonly known as bad design.

Note that I am not talking about memory errors (which are bugs),
but rather resource limitation (which are predictable and can be
accounted for).

Industry level (Microsoft not included) software must check
the result of *every* memory allocation made and act appropriately
for every possible outcome; Again: Crashing is not an option!

This is not really hard. It is more like a pattern. And I like
advice on common practice.

But maybe weekends are a bad time... :-)
Jul 30 '05 #15
Jacob sade:
Note that I am not talking about memory errors (which are bugs),
but rather resource limitation (which are predictable and can be
accounted for).
I wasn't speaking of bugs introduced by you as a programmer in your
own code.

If your system suddenly works against you, changes in resource
limitations could wreak havoc concerning memory and resource needs.

Unless you're designing the entire execution environment, somebody
else debugs a system which you rely on, and many systems can fault.

Industry level (Microsoft not included) software must check
the result of *every* memory allocation made and act appropriately
for every possible outcome; Again: Crashing is not an option!
Yes, how would you otherwise come to the conclusion that further
memory allocations might be impossible and that the severe failure
in memory allocations might raise the need of a controlled restart,
the question is just how clean you can do it, and what help your
system can give you? Restart(either process restart or context restart),
not crash. This is yet a reason why gui and core(s) should be separated
so individual restarts can be done.
This is not really hard. It is more like a pattern. And I like
advice on common practice.
Like isolating functionality to control memory mishaps. If a memory
failure (or any failure which is not related to your coding skills)
occurs in context C then terminate C (and retry). This means a design
where arguments to C will not be changed. Allocate everything within
C from a memory "pool" outside C which can easily be deallocated upon
failure, hence disabling the need for complex deallocation procedures
within C. This gives you control over defined contexts with ease. If
vital contexts repeatly fails, then you might want to think on plan b.

(Context-Oriented Programming =)

You're right, it isn't that hard to control if you are aware.
But maybe weekends are a bad time... :-)


Maybe I should take that as an insult :-)

Tobias
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
Jul 30 '05 #16

"Jacob" <ja***@yahoo.co m> wrote in message
news:MM******** ************@te lenor.com...
somehow. Following my company guidelines inter-library exception
throw/catch is not an option, so I need to use other mechanisms.


this is a stupid nonsensical restriction -- exceptions are intended for
reporting errors out of libraries
Jul 31 '05 #17

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

Similar topics

6
13883
by: kwijibo28 | last post by:
Hi all, I've got a simple question regarding stl containers. Consider this code: std::vector<float> foo; foo.resize(100); How do I know if memory allocation was successful? The resize method returns nothing. I understand that resize does not always allocate
2
2425
by: CoolPint | last post by:
Standard exception classes in C++ have what() which returns const char * and they have constructors accepting string. Where is that string created and when is the string destroyed? In the function below, e is a local object so when the function terminates, the internal string should be gone too, isn't it?
21
7288
by: Stephan | last post by:
why does the following code not work???? after compiling and running it will just say killed after all my memory filled up any suggestions? #include <iostream> using namespace std; void out_of_mem() {
10
2059
by: Steven T. Hatton | last post by:
I read Stroustrup's article of the day: http://www.research.att.com/~bs/C++.html Programming with Exceptions. InformIt.com. April 2001. http://www.research.att.com/~bs/eh_brief.pdf Some of these ideas are finally beginning to sink in. I believe I looked at the same article a while back and decided I wasn't quite ready for it. If I understood things correctly, there seems to be a slight problem with the design of his exception safe...
3
2255
by: Tony Johansson | last post by:
Hello! When you allocate object dynamically which mean on the heap I find that a problem when using exception. What is the prefer method to handle this kind of problem. //Tony
6
2702
by: Fred Zwarts | last post by:
Hello, I am trying to debug some complex debug code. In order to track the use of dynamically allocated memory, I replaced the standard global new and delete operators. (Not for changing the memory allocation algorithm, but for gathering some statistics and to find memory leaks.) This seems to work. However, I noticed that my replacing delete operator is not called
99
5219
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
66
3650
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if (function(socket, args) == -1) { perror("function"); exit(EXIT_FAILURE); } I feel that the ifs destroy the readability of my code. Would it be
24
19101
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array is faster than malloc, but dynamic memory allocation is more flexible. Please comment... thanks.
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10317
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,...
1
7615
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 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...
0
6851
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();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
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
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
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 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...

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.