title: Is it safe to keep C++ pointers in C#?
body: <p>I'm currently working on some C#/C++ code which makes use of invoke. In the C++ side there is a std::vector full of pointers each identified by index from the C# code, for example a function declaration would look like this:</p>
  
  <pre><code>void SetName(char* name, int idx)
  </code></pre>
  
  <p>But now I'm thinking, since I'm working with pointers couldn't I sent to C# the pointer address itself then in code I could do something like this:</p>
  
  <pre><code>void SetName(char*name, int ptr)
  {
     ((TypeName*)ptr)-&gt;name = name;
  }
  </code></pre>
  
  <p>Obviously that's a quick version of what I'm getting at (and probably won't compile).</p>
  
  <p>Would the pointer address be guaranteed to stay constant in C++ such that I can safely store its address in C# or would this be too unstable or dangerous for some reason?</p>