Jump to content

Resizing Vertices & Indices using CreateMesh()


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

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);

 

Link to comment
Share on other sites

  • Solution

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());

 

  • Thanks 1

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...