guess how much memory will be needed and adjust chunk size
reboot hpohl's #2470
Merge pull request #3613 from WalterBright/hpohl-opt

Increase allocation chunk size + minor refactoring