Added progressive pre-alloc

to fix issues for large fles
also vectorized the gain computation