Is there a limit on the size of an array in ruby? [duplicate]
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!
There is not a software limit imposed by Ruby, but there is a limit as to how much the process can support. If you have a regular home server running the Ruby server, it would be able to handle an array until the array became too large, at which point it would begin to 'bog down', lag, crash, etc. On the other hand, if you had an extremely powerful corporate server, it could handle a much larger array, but would still eventually crash/lag if the array became too large for the process and the hardware (memory) to handle.
I don't have any concrete numbers for you, because it all depends on the hardware and software on the server.
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!
精彩评论