free memory

P

pelio

June Lee dixit:
my PC has 2GB memory, Can I write C++ prototype program that run for 2
hour and don't free / delete any memory?

It's a graphics / OpenGL program.

It is not opengl but try it:

int
main()
{
for (;;) { new int[10]; }
}
 
P

Paavo Helde

my PC has 2GB memory, Can I write C++ prototype program that run for 2
hour and don't free / delete any memory?

It's a graphics / OpenGL program.

Sure you can write such a program, if it does not allocate any dynamic
memory then it has no need to delete it either.

But I guess you meant a program which is actually allocating something.
Let's see - 2 hours is 7200 seconds. 2GB divided by 7200 seconds makes ca
300000 bytes per second. So if your program allocates new memory lower
than this rate, it should be possible - theoretically. However, this is
not nice to other applications running at the same time.

Note that your OS most probably has a swap file or partition, which
increases the available memory so you should be able to go over 2GB
limit. OTOH, if your process is 32-bit, then it will run out of address
space, depending on the OS only 1 to 3 of the total 4GB address space
might be available to the user data in the process, and part of this is
taken by non-dynamic data structures. Also, when parts of the memory
start swapping out, the performance of the machine degrades.

So what's your goal? You have a contract by which you are paid for the
program immediately when it has run 2 hours without problems? ;-)

Paavo
 
J

June Lee

my PC has 2GB memory, Can I write C++ prototype program that run for 2
hour and don't free / delete any memory?

It's a graphics / OpenGL program.
 
J

June Lee

I mean I tested it and fix all leaking / infinit loop bugs

that means my program will run in finite memory for 2 hours
 
M

Miguel Gimenez

Paavo Helde escribió:
Sure you can write such a program, if it does not allocate any dynamic
memory then it has no need to delete it either.

But I guess you meant a program which is actually allocating something.
Let's see - 2 hours is 7200 seconds. 2GB divided by 7200 seconds makes ca
300000 bytes per second. So if your program allocates new memory lower
than this rate, it should be possible - theoretically. However, this is
not nice to other applications running at the same time.

Note that your OS most probably has a swap file or partition, which
increases the available memory so you should be able to go over 2GB
limit. OTOH, if your process is 32-bit, then it will run out of address
space, depending on the OS only 1 to 3 of the total 4GB address space
might be available to the user data in the process, and part of this is
taken by non-dynamic data structures. Also, when parts of the memory
start swapping out, the performance of the machine degrades.

So what's your goal? You have a contract by which you are paid for the
program immediately when it has run 2 hours without problems? ;-)

Two hours is the time needed to reach the country border :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top