can anyone help tell me why i run out of memory?
William Labbett

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

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

gnolam

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

Show code.

Dustin Dettmer

What a lame plug.

William Labbett

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

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. ;)

William Labbett

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 ?

Dustin Dettmer

Did install_keyboard fail when you called it?

William Labbett

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

Michael Jensen

what OS/compiler are you using?

William Labbett

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

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

gnolam

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

Thread #591073. Printed from Allegro.cc