Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are allocating your own memory in native code, use <a href="http://msdn.microsoft.com/en-us/library/ms692727.aspx" rel="nofollow noreferrer"><code>CoTaskMemAlloc</code></a> and you can free the pointer in managed code with <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.freecotaskmem" rel="nofollow noreferrer"><code>Marshal.FreeCoTaskMem</code></a>. <code>CoTaskMemAlloc</code> is described as "the only way to share memory in a COM-based application" (see <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366533%28v=vs.85%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/aa366533(v=vs.85).aspx</a> )</p> <p>if you need to use the memory allocated with <code>CoTaskMemAlloc</code> with a native C++ object, you can use <em>placement new</em> to initialize the memory as if the <code>new</code> operator was used. For example:</p> <pre><code>void * p = CoTaskMemAlloc(sizeof(MyType)); MyType * pMyType = new (p) MyType; </code></pre> <p>This doesn't allocate memory with <code>new</code> just calls the constructor on the pre-allocated memory.</p> <p>Calling <code>Marshal.FreeCoTaskMem</code> does not call the destructor of the type (which isn't needed if you just need to free memory); if you need to do more than free memory by calling the destructor you'll have to provide a native method that does that and P/Invoke it. Passing native class instances to managed code is not supported anyway.</p> <p>If you need to allocate memory with some other API, you'll need to expose it in managed code through P/Invoke in order to free it in managed code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload