title: does NewDirectByteBuffer create a copy in native code
body: <p>I am creating two arrays in c++ which will be read in java side: </p>
  
  <pre><code>env-&gt;NewDirectByteBuffer
  env-&gt;NewByteArray
  </code></pre>
  
  <p>Do these functions copy the buffer I send it?
  Do I need to create the buffer on the heap in the c++ side or is it ok to create it on the stack because the jvm will copy it?</p>
  
  <p>for example will this code run ok:</p>
  
  <pre><code>std::string stam = "12345";
  const char *buff = stam.c_str();
  jobject directBuff = env-&gt;NewDirectByteBuffer((void*)buff, (jlong) stam.length() );
  </code></pre>
  
  <p>Another example:</p>
  
  <pre><code>std::string md5 "12345";    
  jbyteArray md5ByteArray = env-&gt;NewByteArray((jsize) (md5.length()));
  env-&gt;SetByteArrayRegion(md5ByteArray, 0, (jsize) (md5.length()), (jbyte*)    
   md5.c_str());
  </code></pre>
  
  <p>string is created on the stack. Will this code always work or do I need to create those strings on the heap and be responsible to delete it after java finishes using it</p>