.net - Marshalling IntRef with P/Invoke -


When I am using the IntPtr to reserve memory and a dynamic range of the original code, the memory After managing at the C # / Managed side and pass it on to my original DLL, is this piece of memory ticked or copied? To wit. If I modify the array within my original code, will I see an amendment in my managed code?

I know that it is not necessary to use IntPtr, but since the array is embedded in a complex structure, it seems more convenient.

There are only valid methods for receiving an IntPtr for memory allocations in a .net program: / P>

  • Using one of the Marshal.AllocXxx () methods. It is not a pinned memory, it is obsolete memory, which is allocated to one of the operating system heap. Generally, the operating system does not support the notion of changing the address of an allocation, once it is made, it is always stuck at the same address. Only garbage collectors have the necessary magic, they can find pointers behind the memory blocks and how to update them.
  • Using GCHandle.AddrOfPinnedObject (). GC heap is called GCHandle.Free (), allocated from the heap, the address will remain constant. Use only if allocation is required in the short run.
  • Using C # Fixed keywords, it is a highly customized version of GCHandle that works without assigning a handle. Specifically obtained from the panic while marking the variable, it will be searched by GC when it runs on the stack, will search the roots. It otherwise has the exact same effect as GCHandle, GC considers the target of the definite statement pinched and will not move the object.

Be careful since the two tablets, especially Fixed This is dangerous because the keyword that requires the unsafe a bar code After execution, it is very important to stop using intraparte, leave the scope of the statement. Runtime is not implemented by the failure mode is completely immutable ExecutionEngineException when the GC shows that the stack has become corrupted. Due to the transfer of the code to the memory block after blocking the code through ITPTR, something else was written.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -