Possible Duplicate:
Array size too big - ruby
Sorry if this has been asked, I looked around but didnt really find what I was looking for.
I am using ruby and mysql to create an array based off of a single column in the mysql table. So for example, say I have a column of user names:
users = []
users.clear
# Update the list of users to follow
res = dbh.query("SELECT user FROM usernameDB")
while row = res.fetch_row do
users << row[0] #adds each user to the array
end
This has worked fine up until now, when we started recieving a lot more users. Now the code gives me unknown errors.
In an attempt to troubleshoot, I simply commented out most of it and built the array with just a couple of user names, and everything worked again. So my question is, is there a limit to the number or items in a ruby array?
Thanks!
The theoretical maximum Java array size is 2,147,483,647 elements. To find the size of a Java array, query an array's length property.
Size of an array If you create an array by initializing its values directly, the size will be the number of elements in it. Thus the size of the array is determined at the time of its creation or, initialization once it is done you cannot change the size of the array.
The array size is limited to a total of 4 billion elements, and to a maximum index of 0X7FEFFFFF in any given dimension (0X7FFFFFC7 for byte arrays and arrays of single-byte structures). . NET Framework only: By default, the maximum size of an Array is 2 gigabytes (GB).
select { array. count } is a nested loop, you're doing an O(n^2) complex algorithm for something which can be done in O(n). You're right, to solve this Skizit's question we can use in O(n); but in order to find out which elements are duplicated an O(n^2) algo is the only way I can think of so far.
Take a look at this other post: Array size too big - ruby. The size of 600 million was too big, but 500 million worked.
How big of an array are you working with? The problem may be that you're running out of memory!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With