title: The difference between sizeof and .size() for a vector c++
body: <p>I'm implementing a MPI code and I'm using <code>MPI_Bcast</code> function. One of the function's components is the number of data sent which is here the size of a vector called <code>l_nMinplacesPos</code>. I want to share the size of this vector. I tried once <code>sizeof l_nMinplacesPos</code> which returned 32 and when I used <code>l_nMinplacesPos.size()</code> I got 2 as a size of the vector!!!. I'm confused which one of them displays the actual size of the vector? and what is the difference between both of them?</p>
  
  <pre><code>void ParaStochSimulator::broad_casting(long j){
  std::cout &lt;&lt; "i'm broad_casting" &lt;&lt; std::endl;
  l_nMinplacesPos = (*m_pcTransitionsInfo)[j]-&gt;GetManipulatedPlaces();
  double val;
  l_anMarking.reserve(l_nMinplacesPos.size());
  for (auto lnpos : l_nMinplacesPos)
  {
      val = m_anCurrentMarking[lnpos];
      l_anMarking.push_back(val);
  }
  for (auto marking : l_anMarking)
  {
      std::cout &lt;&lt; marking &lt;&lt; std::endl;
  }
  MPI_Bcast(&amp;l_anMarking, sizeof l_nMinplacesPos, MPI_DOUBLE, 0,   MPI_COMM_WORLD); //-&gt;here i used  l_nMinplacesPos.size() instead.
  </code></pre>
  
  <p>}</p>
  
  <pre><code>void ParaStochSimulator::SimulateSingleRun()
  {
  //prepare a run
  PrepareRun();
  while ((m_nCurrentTime &lt; m_nOutputEndPoint) &amp;&amp; IsSimulationRunning())
      {
      deterMinTau();
      if (mnprocess_id == 0)
      {
          SimulateSingleStep1();
          std::cout &lt;&lt; "current time:*****" &lt;&lt; m_nCurrentTime &lt;&lt; std::endl;
          broad_casting(m_nMinTransPos);
          std::cout &lt;&lt; "size of mani place :" &lt;&lt; sizeof l_nMinplacesPos &lt;&lt; std::endl;
  
      }
  }
  PostProcessRun();
  MPI_Bcast(&amp;l_anMarking, sizeof l_nMinplacesPos, MPI_DOUBLE, 0, MPI_COMM_WORLD); //-&gt;here i used l_nMinplacesPos.size() instead.
  std::cout &lt;&lt; "size of mani place :" &lt;&lt; sizeof l_nMinplacesPos &lt;&lt; std::endl;
  
  
  }
  </code></pre>