Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

IMalloc (Interfaces)
 
.
Summary
The IMalloc interface allocates, frees, and manages memory.

C# Definition:

/// <summary>
/// C# definition of the IMalloc interface.
/// </summary>
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("00000002-0000-0000-C000-000000000046")]
internal interface IMalloc
{
    /// <summary>
    /// Allocate a block of memory
    /// </summary>
    /// <param name="cb">Size, in bytes, of the memory block to be allocated.</param>
    /// <returns>a pointer to the allocated memory block.</returns>
    [PreserveSig]
    IntPtr Alloc(
        [In] UInt32 cb);

    /// <summary>
    /// Changes the size of a previously allocated memory block.
    /// </summary>
    /// <param name="pv">Pointer to the memory block to be reallocated</param>
    /// <param name="cb">Size of the memory block, in bytes, to be reallocated.</param>
    /// <returns>reallocated memory block</returns>
    [PreserveSig]
    IntPtr Realloc(
        [In] IntPtr pv,
        [In] UInt32 cb);

    /// <summary>
    /// Free a previously allocated block of memory.
    /// </summary>
    /// <param name="pv">Pointer to the memory block to be freed.</param>
    [PreserveSig]
    void Free(
        [In] IntPtr pv);

    /// <summary>
    /// This method returns the size, in bytes, of a memory block previously allocated with IMalloc::Alloc or IMalloc::Realloc.
    /// </summary>
    /// <param name="pv">Pointer to the memory block for which the size is requested</param>
    /// <returns>The size of the allocated memory block in bytes.</returns>
    [PreserveSig]
    UInt32 GetSize(
        [In] IntPtr pv);

    /// <summary>
    /// This method determines whether this allocator was used to allocate the specified block of memory.
    /// </summary>
    /// <param name="pv">Pointer to the memory block</param>
    /// <returns>
    /// 1 - allocated
    /// 0 - not allocated by this IMalloc Instance.
    /// -1 if DidAlloc is unable to determine whether or not it allocated the memory block.
    /// </returns>
    [PreserveSig]
    Int16 DidAlloc(
        [In] IntPtr pv);

    /// <summary>
    /// Minimizes the heap by releasing unused memory to the operating system.
    /// </summary>
    [PreserveSig]
    void HeapMinimize();
}
interface IMalloc {
    // Allocate a block of memory
    // Return value: a pointer to the allocated memory block.
    [PreserveSig]
    IntPtr Alloc(
       [In] UInt32 cb); // Size, in bytes, of the memory block to be     
             // allocated.

VB Definition:

<Runtime.InteropServices.ComImport()> _
<Runtime.InteropServices.InterfaceType(Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)> _
<Runtime.InteropServices.Guid("00000002-0000-0000-C000-000000000046")> _
Public Interface IMalloc
    // Changes the size of a previously allocated memory block.
    // Return value: reallocated memory block
    [PreserveSig]
    IntPtr Realloc(
        [In] IntPtr pv,  // Pointer to the memory block to be reallocated
        [In] UInt32 cb); // Size of the memory block, in bytes, to be
             // reallocated.

    ''' <summary>
    ''' Allocate a block of Memory.
    ''' </summary>
    ''' <param name="cb">Size, in bytes, of the memory block to be allocated.</param>
    ''' <returns>Returns a pointer to the allocated memory block.</returns>
    <Runtime.InteropServices.PreserveSig()> Function Alloc(ByVal cb As UInt32) As IntPtr
    // Free a previously allocated block of memory.
    [PreserveSig]
    void Free(
        [In] IntPtr pv); // Pointer to the memory block to be freed.

    ''' <summary>
    ''' Changes the size of the allocated memory block.
    ''' </summary>
    ''' <param name="pv">Pointer to the memory block to be reallocated.</param>
    ''' <param name="cb">Size of the memory block, in bytes, to be reallocated.</param>
    ''' <returns>Returns the reallocated memory block.</returns>
    <Runtime.InteropServices.PreserveSig()> Function Realloc(ByVal pv As IntPtr, ByVal cb As UInt32) As IntPtr
    // This method returns the size, in bytes, of a memory block
    // previously
    // allocated with IMalloc::Alloc or IMalloc::Realloc.
    // Return value: The size of the allocated memory block in bytes.
    [PreserveSig]
    UInt32 GetSize(
        [In] IntPtr pv); // Pointer to the memory block for which the size is
            // requested.

    ''' <summary>
    ''' Free a previously allocated block of memory.
    ''' </summary>
    ''' <param name="pv">Pointer to the memory block to be freed.</param>
    <Runtime.InteropServices.PreserveSig()> Sub Free(ByVal pv As IntPtr)
    // This method determines whether this allocator was used to allocate
    // the specified block of memory.
    // Return value: 1 - allocated 0 - not allocated by this IMalloc Instance.
    // -1 if DidAlloc is unable to determine whether or not it allocated the memory block.
    [PreserveSig]
    Int16 DidAlloc(
        [In] IntPtr pv); // Pointer to the memory block

    ''' <summary>
    ''' This method returns the size, in bytes, of a memory block previously allocated with IMalloc::Alloc or IMalloc::Realloc.
    ''' </summary>
    ''' <param name="pv">Pointer to the memory block for which the size is requested.</param>
    ''' <returns>Returns the size of the allocated memory block in bytes.</returns>
    <Runtime.InteropServices.PreserveSig()> Function GetSize(ByVal pv As IntPtr) As UInt32
    // Minimizes the heap by releasing unused memory to the operating system.
    [PreserveSig]
    void HeapMinimize();
    }

VB Definition:

<Runtime.InteropServices.ComImport()> _

<Runtime.InteropServices.InterfaceType(Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)> _

<Runtime.InteropServices.Guid("00000002-0000-0000-C000-000000000046")> _

Public Interface IMalloc

    ''' <summary>
    ''' This method determines whether this allocator was used to allocate the specified block of memory.
    ''' Allocate a block of Memory.
    ''' </summary>
    ''' <param name="pv">Pointer to the memory block.</param>
    ''' <returns>1 - allocated 0 - not allocated by this IMalloc Instance.</returns>
    <Runtime.InteropServices.PreserveSig()> Function DidAlloc(ByVal pv As IntPtr) As Int16
    ''' <param name="cb">Size, in bytes, of the memory block to be allocated.</param>
    ''' <returns>Returns a pointer to the allocated memory block.</returns>
    <Runtime.InteropServices.PreserveSig()> Function Alloc(ByVal cb As UInt32) As IntPtr

    ''' <summary>
    ''' 'Minimizes the heap by releasing unused memory to the operating system.
    ''' Changes the size of the allocated memory block.
    ''' </summary>
    <Runtime.InteropServices.PreserveSig()> Sub HeapMinimize()
    ''' <param name="pv">Pointer to the memory block to be reallocated.</param>
    ''' <param name="cb">Size of the memory block, in bytes, to be reallocated.</param>
    ''' <returns>Returns the reallocated memory block.</returns>
    <Runtime.InteropServices.PreserveSig()> Function Realloc(ByVal pv As IntPtr, ByVal cb As UInt32) As IntPtr

End Interface
    ''' <summary>
    ''' Free a previously allocated block of memory.
    ''' </summary>
    ''' <param name="pv">Pointer to the memory block to be freed.</param>
    <Runtime.InteropServices.PreserveSig()> Sub Free(ByVal pv As IntPtr)

    ''' <summary>
    ''' This method returns the size, in bytes, of a memory block previously allocated with IMalloc::Alloc or IMalloc::Realloc.
    ''' </summary>
    ''' <param name="pv">Pointer to the memory block for which the size is requested.</param>
    ''' <returns>Returns the size of the allocated memory block in bytes.</returns>
    <Runtime.InteropServices.PreserveSig()> Function GetSize(ByVal pv As IntPtr) As UInt32

    ''' <summary>
    ''' This method determines whether this allocator was used to allocate the specified block of memory.
    ''' </summary>
    ''' <param name="pv">Pointer to the memory block.</param>
    ''' <returns>1 - allocated 0 - not allocated by this IMalloc Instance.</returns>
    <Runtime.InteropServices.PreserveSig()> Function DidAlloc(ByVal pv As IntPtr) As Int16

    ''' <summary>
    ''' 'Minimizes the heap by releasing unused memory to the operating system.
    ''' </summary>
    <Runtime.InteropServices.PreserveSig()> Sub HeapMinimize()

End Interface

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions