memory optimization for random terrain