SpiderPig Posted January 21, 2023 Share Posted January 21, 2023 I'm creating vertices and indices for meshes on a separate thread and reserve more than enough space so there is no memory reallocation in the process. Question is should the vertices and indices be shrunk so that their capacity is the same as there size for CreateMesh()? At first I thought yes, but then I thought CreateMesh() is most likely looping through the vectors up to there size and transferring the data to a format to send to the GPU? Or is there a memcopy under the hood that transfers the whole capacity? shinrk_to_fit() takes time and I'd like to do without it. It works without it, yes. But is it a good idea? vector<Vertex> vertices; vector<unsigned int> indices; int max_vertices = 1000; int max_indices = 1000; vertices.reserve(max_vertices); indices.reserve(max_indices); //push_back vertices & indices to require size if(vertices.size() < vertices.capacity()){ vertices.shrink_to_fit(); }//Needed for CreateMesh()? if(indices.size() < indices.capacity()){ indices.shrink_to_fit(); }//Needed for CreateMesh()? //Data is returned from thread //On main thread CreateMesh(MESH_TRIANGLES, vertices, indices); Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted January 21, 2023 Solution Share Posted January 21, 2023 It looks like copying a vector does not copy the capacity, so there is no need to call shrink_to_fit: std::vector<int> t; t.reserve(1000); auto a = t; Print(t.capacity()); Print(a.capacity()); 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.