:有人可以解釋我遇到一些麻煩,此代碼Marshal.StructureToPtr
//Creating a new ImageElement Struct
ImageElement oElement = new UM0516.ImageElement();
//Create a pointer and allocate enough room for the struct type
IntPtr pElement = Marshal.AllocHGlobal(Marshal.SizeOf(new UM0516.ImageElement()));
//Copy the contents of the struct into the allocated memory space
Marshal.StructureToPtr(oElement, pElement, true);
//Function that takes a file pointed to by handle, and does some sweet sweet things
//And returns a loaded struct pointed to by pElement
FILES_GetImageElement(handle, el, out pElement);
這裏就是我感到困惑:我會單步執行代碼,我稱之爲後,去年函數(這應該改變pElement指向的內存中的一些位),我看到oElement變化了!?我認爲Marshal.StructureToPtr將數據從託管結構「複製」到內存中。那麼這兩個地點實際上是一樣的嗎?由pElement指向的受管struct oElement和分配的內存?
-1寫「幫助YO」和「庫爾耶」。 – 2009-04-09 21:19:10