C++ fstream writing to file very slow -
i have 2d world in game consisting of tiles. whenever make new world initialize array of 48 million tiles
short worldgrid[48000000];
i set value 48 million, write values file this:
std::fstream save("game_save", std::fstream::out); (int x = 0; x < 48000000; x++) { save << world.worldgrid[x]; save << " "; } save.close();
it's 48 million values, each 1 2 bytes. 96 million bytes, or 96 megabtyes. problem process inside loop alone takes 2 minutes complete on ssd. don't feel should take 2 minutes , 5 seconds write 96mb worth of data onto file. if has advice i'd appreciate it.
try writing array @ once, instead of 2 bytes-at-a-time.. like:
save.write(world.worldgrid, sizeof(worldgrid));
see the docs
Comments
Post a Comment