The while loop is from save_load_regressor in gd.cc, and the resource management part is from void finish(vw& all) in parse_args.cc. I decided to only move here the necessary codes from those two functions. For example, if we directly call the save_load_regressor function, we need to add all the mask thing into that function. We need to initialize the weight vector even for the temp vw struct since it is used in the loop. Also that function is generic for both save and load, but we only need the load part here.
For the resource management part, if we directly call finish(*vw_temp), there will be a number of seg fault because only a part of vw members are initialized after new vw(). To directly use the finish function, we may need to initialize everything by ourselves, which might be more messy than just destroy things created by new vw().