![]() |
|
can anyone help tell me why i run out of memory? |
William Labbett
Member #4,486
March 2004
![]() |
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
![]() |
If you posted relevant code, it would help you get better responses. |
gnolam
Member #2,030
March 2002
![]() |
First, completely baseless guess: you're allocating too much on the stack. Show code. -- |
ImLeftFooted
Member #3,935
October 2003
![]() |
What a lame plug. |
William Labbett
Member #4,486
March 2004
![]() |
Okay thanks for the willingness to help. P and N are #defines 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
![]() |
And first prize goes to... me! [EDIT] 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
Member #4,486
March 2004
![]() |
yeh but the keypressed() function never works even when a key is pressed (exit(1)) About the dynamic allocation : I thought automatic variables come and go with function calls. Am I missing something ?
|
ImLeftFooted
Member #3,935
October 2003
![]() |
Did install_keyboard fail when you called it? |
William Labbett
Member #4,486
March 2004
![]() |
No, I just checked for that but it calls OK.
|
Michael Jensen
Member #2,870
October 2002
![]() |
what OS/compiler are you using?
|
William Labbett
Member #4,486
March 2004
![]() |
Using Windows XP with gcc v 2.95.3-6 (mingw special).
|
HoHo
Member #4,534
April 2004
![]() |
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 __________ |
gnolam
Member #2,030
March 2002
![]() |
Well, GCC 3.4 at least. There's no official GCC 4 for MinGW. -- |
|