473,386 Members | 1,652 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,386 software developers and data experts.

try to maka a program run out of memory

Hello experts!!

I have written a small program that I hope will run out of memory(just for
testing) because i have deliberately removed the delete of the allocated
memory but it will not run out of memory.
So my question is can you see why not this program will run out of memory.
It consist of three files these are start.cpp,test.h and slask.h

// Here is the file containing the main funtion called start.cpp
#include "test.h"
main()
{
Test testobj;
for (long i =0; i<999999999; i++)
testobj.foo();
}

//Here is file test.h containing the class definition of class Test
#include "slask.h"
class Test
{
public:
void foo()
{ s = new Slask(); }
private:
Slask* s;
};

//Here is the last file named slask.h containg the class definition of class
Slask.
class Slask
{
public:
private:
char namn1[1000];
char namn2[1000];
};

Many thanks
//Tony
Jul 23 '05 #1
2 2088
Tony Johansson wrote:
I have written a small program that I hope will run out of memory(just for
testing) because i have deliberately removed the delete of the allocated
memory but it will not run out of memory.
So my question is can you see why not this program will run out of memory.
It consist of three files these are start.cpp,test.h and slask.h


Hi,

i can only talk about the linux behaviour of this program:

it runs out of memory if you have no swap-memory. I ran the program and
my harddisk got very busy, that means that the system uses the swap-area
on the harddisk to allocate new items. I didn`t look what happens if the
system is out of swap ... could take hours

regards marbac

Jul 23 '05 #2
Tony Johansson schrieb:
Hello experts!!

I have written a small program that I hope will run out of memory(just for
testing) because i have deliberately removed the delete of the allocated
memory but it will not run out of memory.
So my question is can you see why not this program will run out of memory.
It consist of three files these are start.cpp,test.h and slask.h
One possibility might be your impatience ;-)
I added a try...catch around your loop in main and got a std::bad_alloc
exception as expected...it took this box (Athlon XP 2400+, 256MB, WinXP)
some 15 minutes to get there though. Meanwhile I could see the C++
library's (mingw) exponential allocator at work: at first the program
almost immediately hogged 256MB, then 512MB, 1GB where it became really
slow due to swapping and new allocations were again decreasing in size
(by a factor of 0.5) which makes sense when you take into account that
there is an absolute maximum of 2GB of per process memory on this
platform, which is exactly what the program had allocated when the
exception was thrown.
If your platform doesn't have such a "low" limit, it could take a lot
longer run out of memory. To speed things up, you could deactivate any
swap...another one would be to drastically increase Slask's size or
simply alloc blocks of a GB or so if you want to force an OOM condition.

Another possibility is that you're using an old compiler that doesn't
throw std::bad_alloc but returns a null pointer when the allocation
fails. Did you check that? Given that your compiler accepted the below
error (implicit int is not part of Standard C++), maybe it has other
non-conforming behaviour too...
// Here is the file containing the main funtion called start.cpp
#include "test.h"
main() int main()
{
Test testobj;
for (long i =0; i<999999999; i++)
testobj.foo();
}


Cheers,
Malte
Jul 23 '05 #3

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

Similar topics

4
by: ulysses | last post by:
hi, I'm working in python 5 months. I think it's very cool language. I do a p2p python program GUI. First I make a software by wxpython. But I find wxpython use many many memory. Second I use...
14
by: J. Campbell | last post by:
what happens to allocated memory when a program terminates before the memory is released. For example: int main(){ int* array; int a_size = 1000; array = new int; for(int i = 0; i < a_size;...
29
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this...
2
by: Asfar | last post by:
Hi, I have a VS2005 windows program written in c#. In this program I have an array list which stores many DataTable's. When I first run the pogram the arraylist is loaded with datatables. At...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
6
by: dspfun | last post by:
I would like to analyze my running c-program. What I would like to know for example is the range of the entire address space of my running c-program (memory reserved for/by the running program),...
12
by: elty123 | last post by:
I have a small C# program (about 400 lines of code) that is only 28kb after compiled. However when it runs (takes a whole 5 seconds) it takes up nearly 20MB of memory and I don't see why. ...
39
by: Ravi | last post by:
Can you all please suggest a program which tell us the range of memry addresses occupied by the given c program?
19
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...

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.