![]() |
| ||
| need help with prime hi, I was trying to implement the sieve of eroathoses (I know I spelt this wrong) and it works. But i was trying to find all prime under 2 million. The .cmd for visual studio just corrupts if I try to find all prime under 2million. I am guessing It's because overflow or something but I don't know for sure. can you give me some hints on how to fix my code so the program won't corrupt. here is the code: #include<iostream> thanks |
| ||
| Re: need help with prime Yeay...maks array size is 65535 or 65536...i dont know exactly... |
| ||
| Re: need help with prime what??? |
| ||
| Re: need help with prime ur using 32 bit compiler rit... see this...
|
| ||
| Re: need help with prime Quote:
the program corrupts, but if i try to find all prime number below say 2000, it works perfectly. Try the program to see what i mean. I don't get why it does not work for a large number. |
| ||
| Re: need help with prime Static memory space is generally very limited, if you want to create large array sizes then you need to use dynamic memory. __int64 *array = new __int64[2000000];But be sure to delete the array afterwards delete []array; Chris |
| ||
| Re: need help with prime Quote:
|
| ||
| Re: need help with prime new allocates dynamic memory (did i choose the right words?). |
| ||
| Re: need help with prime So it's like i'm telling the computer to make extra memory by saying __int64 *array = new __int64[2000000]; Is it the 'new' that tells the computer to make extra room? |
| ||
| Re: need help with prime When you create a pointer to a type you reserve enough space in memory for the the variable. When you call new you actually allocate the memory to the program so it cannot be used by another program. Chris |
| All times are GMT -4. The time now is 2:59 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC