This topic has not yet been rated - Rate this topic

IMallocSpy Interface

Enables monitoring of memory allocation, detection of memory leaks, and simulation of memory failure in calls to IMalloc methods. For more information, see IMallocSpy.

Namespace: Microsoft.VisualStudio.OLE.Interop
Assembly: Microsoft.VisualStudio.OLE.Interop (in microsoft.visualstudio.ole.interop.dll)

[GuidAttribute("0000001D-0000-0000-C000-000000000046")] 
[InterfaceTypeAttribute(1)] 
public interface IMallocSpy
/** @attribute GuidAttribute("0000001D-0000-0000-C000-000000000046") */ 
/** @attribute InterfaceTypeAttribute(1) */ 
public interface IMallocSpy
GuidAttribute("0000001D-0000-0000-C000-000000000046") 
InterfaceTypeAttribute(1) 
public interface IMallocSpy
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Using IMallocSpy in c#
Is there any demo code available how to use IMallocSpy in C#?

i tryed this:

    internal class MallocSpy : Microsoft.VisualStudio.OLE.Interop.IMallocSpy
    {
        public uint PreAlloc(uint cbRequest)
        {
            return cbRequest;
        }

        public IntPtr PostAlloc(IntPtr pActual)
        {
            return pActual;
        }

        public IntPtr PreFree(IntPtr pRequest, int fSpyed)
        {
            return pRequest;
        }

        public void PostFree(int fSpyed)
        {
        }

        public uint PreRealloc(IntPtr pRequest, uint cbRequest, out IntPtr ppNewRequest, int fSpyed)
        {
            ppNewRequest = pRequest;
            return cbRequest;
        }

        public IntPtr PostRealloc(IntPtr pActual, int fSpyed)
        {
            return pActual;
        }

        public IntPtr PreGetSize(IntPtr pRequest, int fSpyed)
        {
            return pRequest;
        }

        public uint PostGetSize(uint cbActual, int fSpyed)
        {
            return cbActual;
        }

        public IntPtr PreDidAlloc(IntPtr pRequest, int fSpyed)
        {
            return pRequest;
        }

        public int PostDidAlloc(IntPtr pRequest, int fSpyed, int fActual)
        {
            return fActual;
        }

        public void PreHeapMinimize()
        {
        }

        public void PostHeapMinimize()
        {
        }
    }

---snip---

        [DllImport("ole32.dll")]
        private static extern int CoRegisterMallocSpy(IntPtr pMallocSpy);

---snip---

            MallocSpy mallocSpy = new MallocSpy();

            IntPtr mallocSpyIterfacePointer = Marshal.GetComInterfaceForObject(mallocSpy, typeof (IMallocSpy));
            
            int result = CoRegisterMallocSpy(mallocSpyIterfacePointer);

---snip---
            
            myMalloc.Alloc(1);


when i call this it works fine, PreAlloc is called, PostAlloc is called but when postalloc returns i got a "FatalExecutionEngineError"


what must i do to get this work?