dynamically malloc/free arrays to avoid stack overflow on windows.
starting with 0 for array index will give a reasonable value for 'first'.
Merge pull request #2976 from talentraspel/19751

dynamically malloc/free arrays to avoid stack overflow on windows.