Problem with overflowing character tables in Ruby

I wrote some Ruby code to import Google n-gram data into a hash table, matching the slot unigrams with their corresponding counts. I use characters, not strings for keys. I have been running this code for a long time in linux box without any problems. Running on my Mac this morning gave a character table overflow error after downloading about 2 million key-value pairs. I do not understand what causes this error. Anyone have suggestions on what could be causing? I am running Ruby 1.9.1 under OS X 10.5.8.

+4
source share
2 answers

64-bit difference. 32-bit ruby? I suspect this due to your observation

an error occurred overflowing the symbol table after loading about 2 million key-value pairs

If so, there is nothing you can do about it, but using your own ruby ​​64-bit assembly if strings are not an option due to application design. Otherwise, you have to go with the lines. The conversion is simple:

:symbol.to_s == "symbol" "symbol".to_sym == :symbol 
+1
source

When using Symbol for keys instead of String, it is usually more efficient, the amount of efficiency achieved is proportional to the level of duplication. Since your keys are by definition unique, you should probably just use the String keys to avoid jamming the character table filled with elements.

+2
source

Source: https://habr.com/ru/post/1300908/