• Post Reply Bookmark Topic Watch Topic
  • New Topic

array index  RSS feed

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

code shows error as "possible loss of precision" as am working with long type.but need to have my array size as 10^10 suggest me some other logic?
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:

Incorrect.. That would be 10*10 and not 10^10.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really have 10^10 items or is your data sparsely populated?
You could use a random access file.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good spot.
Bairava, avoid my previous post, it was wrong. You were required 10^10. Overlooked.

Will go sleep a bit earlier this night.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bairava surya wrote:code shows error as "possible loss of precision" as am working with long type.but need to have my array size as 10^10 suggest me some other logic?

That is not possible, because array indices are int in Java which means that the maximum array size is 2^31 - 1 = 2,147,483,647 elements, which is smaller than 10,000,000,000.

Why do you need to be able to create an array with 10 billion elements? Suppose that this would be possible, then you'd need a computer with a LOT of memory to do that. Since an int takes up 4 bytes, you'd have to have at least 40 billion bytes (about 37.25 GB) RAM for an array with 10 billion ints. Does your computer have that much RAM?

you should design your program in a different way, so that you don't need an array this big.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!