Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » can anyone help tell me why i run out of memory?

This thread is locked; no one can reply to it. rss feed Print
can anyone help tell me why i run out of memory?
William Labbett
Member #4,486
March 2004
avatar

hi There,

I've been trying to get better at programming by way of writing some functions for handling numbers bigger than unsigned ints. I wanted to do this for various purposes - factorising large composite numbers and also for a search for an odd perfect number ( http://www.oddperfect.org/ ). My program works well but I always get OUT OF MEMORY errors when doing large searches. It's not strictly allegro related but I was wondering if anyone would be willing to take a look at my code to see if they could tell why this is happening ?

thanks

BAF
Member #2,981
December 2002
avatar

If you posted relevant code, it would help you get better responses.

gnolam
Member #2,030
March 2002
avatar

First, completely baseless guess: you're allocating too much on the stack.

Show code.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

ImLeftFooted
Member #3,935
October 2003
avatar

What a lame plug.

William Labbett
Member #4,486
March 2004
avatar

Okay thanks for the willingness to help.

P and N are #defines
The program basically chooses every combination of P dinstinct primes from a ordered list of N primes and then works out 1. The product. (easyily done) and then 2. The sum of all the products divisors and then plot the results on a loglog
graph.
BTW I know an odd perfect number can't be square free but I'm still interested in these numbers (products of dinstinst primes) and besides I'm just testing my program for more relevant searching later.

I've got two questions I'd really love to have answered :-

1. Why it runs out of memory.

You have to change N in action.c to about 3000 to see this.

2. Why the lines

if(key[KEY_Z])
            save_bitmap("graph.bmp", graph, palette);

don't work. I need this ATM because I can then save the results before the program crashes or if I only want to run it a certain distance.

Also, If you want to see what the program's doing, change WATCH_RESULTS to 1.

Hoping for help, Will

gnolam
Member #2,030
March 2002
avatar

And first prize goes to... me!
Allocate your arrays dynamically and you'll stop running out of memory.

[EDIT]
As for point 2, I grepped for save_bitmap in your code and found this:

Quote:

      if(keypressed())
            exit(1);

         if(key[KEY_Z])
            exit(1);

         if(number_of_composites % 10000 == 0) {
            save_bitmap("graph.bmp", graph, palette);
      
         }

Do think about what happens when a key is pressed, and you'll see why your if(key[KEY_Z]) never gets executed. ;)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

William Labbett
Member #4,486
March 2004
avatar

yeh but the keypressed() function never works even when a key is pressed (exit(1))
isn't called.
None of the keyboard routines work in that file.

About the dynamic allocation : I thought automatic variables come and go with function calls. Am I missing something ?

ImLeftFooted
Member #3,935
October 2003
avatar

Did install_keyboard fail when you called it?

William Labbett
Member #4,486
March 2004
avatar

No, I just checked for that but it calls OK.

Michael Jensen
Member #2,870
October 2002
avatar

what OS/compiler are you using?

William Labbett
Member #4,486
March 2004
avatar

Using Windows XP with gcc v 2.95.3-6 (mingw special).
Perhaps the compiler's too old but it's the one I've always used with allegro 4.0

HoHo
Member #4,534
April 2004
avatar

Well, it might help if you would upgrade to at least GCC 4 and Allegro 4.2 series, they are both around 5 or more years newer than the ones you are using :P

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

gnolam
Member #2,030
March 2002
avatar

Well, GCC 3.4 at least. There's no official GCC 4 for MinGW.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Go to: