Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Array length of a long value
Index -> Programming, Java -> Java Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Naveg




PostPosted: Wed Nov 02, 2005 6:45 pm   Post subject: Array length of a long value

Is it at all possible to have an array that has a length of a long value?? So far all my research has shown that only ints can be the index of an array....

If not, how would I go about storing a "long" number of things?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Nov 02, 2005 7:01 pm   Post subject: (No subject)

ArrayList also appears to be limited to "int" length.

I'd suggest reconsidering why you're storing that much at one time. That would be using massive amount of memory.
Naveg




PostPosted: Wed Nov 02, 2005 7:22 pm   Post subject: (No subject)

well, i have an assignment to find all the primes up to an inputted number...and i thought i would use the sieve of eratosthenes. Use a boolean array, start all at true, gradually eliminate composite numbers, output all remaining "true" indexes
wtd




PostPosted: Wed Nov 02, 2005 7:36 pm   Post subject: (No subject)

Do you expect such a large input number?
Naveg




PostPosted: Wed Nov 02, 2005 9:10 pm   Post subject: (No subject)

My teacher said to use longs so he can test the efficiency with larger numbers.
wtd




PostPosted: Wed Nov 02, 2005 9:38 pm   Post subject: (No subject)

Then you may have to try a different strategy. Smile
Naveg




PostPosted: Wed Nov 02, 2005 10:20 pm   Post subject: (No subject)

Well...would there be any other way to implement the sieve of eratosthenes without using an array?
beard0




PostPosted: Wed Nov 02, 2005 11:21 pm   Post subject: (No subject)

Naveg wrote:
Well...would there be any other way to implement the sieve of eratosthenes without using an array?


No. You could however use the sieve of eratosthenes using a two dimmensional array where

code:
virtualArray[longValue] = actualArray[longValue / maxInt][longValue % maxInt]
Sponsor
Sponsor
Sponsor
sponsor
GlobeTrotter




PostPosted: Wed Nov 02, 2005 11:37 pm   Post subject: (No subject)

What about using a linked list?
rizzix




PostPosted: Thu Nov 03, 2005 1:53 am   Post subject: (No subject)

GlobeTrotter wrote:
What about using a linked list?
That would slow the algorithm down... the faster alternatives would be ArrayList or Vector.. but then again.. i think they too fall under the same restriction.
wtd




PostPosted: Thu Nov 03, 2005 1:59 am   Post subject: (No subject)

rizzix wrote:
GlobeTrotter wrote:
What about using a linked list?
That would slow the algorithm down... the faster alternatives would be ArrayList or Vector.. but then again.. i think they too fall under the same restriction.


They do.
Naveg




PostPosted: Thu Nov 03, 2005 5:31 pm   Post subject: (No subject)

how then do people have programs that can find primes up to massively huge numbers like 100000000000 using the sieve of eratosthenes? Do they not use arrays?

I'm researching a different algorithm for finding primes to try and accomodate a larger range of values without sacrificing speed....
wtd




PostPosted: Thu Nov 03, 2005 5:36 pm   Post subject: (No subject)

Naveg wrote:
how then do people have programs that can find primes up to massively huge numbers like 100000000000 using the sieve of eratosthenes? Do they not use arrays?


They don't use Java?
Naveg




PostPosted: Thu Nov 03, 2005 5:45 pm   Post subject: (No subject)

wtd wrote:
Naveg wrote:
how then do people have programs that can find primes up to massively huge numbers like 100000000000 using the sieve of eratosthenes? Do they not use arrays?


They don't use Java?


Figured you'd say that. But in a language like C++, do arrays take up less RAM? Or are the other data structures in C++ just far faster than those of Java?
wtd




PostPosted: Thu Nov 03, 2005 5:48 pm   Post subject: (No subject)

Well, in C and C++, the problem is that arrays are glorified pointers. On a 32-bit machine, array indexes can only be 32-bit integers.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 25 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: