CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: std::vector::emplace_back vs std::vector::push_back

Threaded View

  1. #1
    Join Date
    Oct 2017
    Posts
    43

    [SOLVED]std::vector::emplace_back vs std::vector::push_back

    Well i just figured out there's a emplace_back method than does same thing as push_back after 4 years messing around with c++. Which one is faster or which one should I use. Currently i use emplace_back like this to retrive vertices data from aiScene of Assimp to my verticeData vector like this.
    Code:
    for (uint32_t numOfVertexComponet = 0; numOfVertexComponet < vertexComponent.size(); ++numOfVertexComponet)
    			{
    				if (vertexComponent[numOfVertexComponet] == VERTEX_COMPONENT_POSITION)
    				{
    					aiVector3D position = mesh->mVertices[numOfVertices];
    
    					verticesData.emplace_back(position.x);
    					verticesData.emplace_back(position.y);
    					verticesData.emplace_back(position.z);
    				}
    				else if (vertexComponent[numOfVertexComponet] == VERTEX_COMPONENT_NORMAL)
    				{
    					aiVector3D normal = mesh->mNormals[numOfVertices];
    
    					verticesData.emplace_back(normal.x);
    					verticesData.emplace_back(normal.y);
    					verticesData.emplace_back(normal.z);
    				}
    			}
    Last edited by noobofcpp; April 16th, 2021 at 04:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)