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)
Assembly: Microsoft.VisualStudio.OLE.Interop (in microsoft.visualstudio.ole.interop.dll)
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?
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?
- 4/12/2007
- Carsten Jendro