Memory problem using GetAdaptersInfo?

Hi,

I'm programming on a Samsung i730 with evc4. I've been monitoring memory usage when calling GetAdaptersInfo and I've noticed that it will randomly bump up the memory anywhere between 0-8192 b reguardless of the results I get. I do not know how to recover this memory. Since my program will be calling this function often, it will slowly consume all the memory. Does anyone know why this might happen

Here is some code:

IP_ADAPTER_INFO* aInfo= 0;
ULONG size = 0;
DWORD result = GetAdaptersInfo(aInfo, &size);
...
delete [] aInfo;

after this, the memory use can go up by any of 0, 4096, or 8192 bytes (bits )


Any help is much appreciated. Thanks.

TomC


Answer this question

Memory problem using GetAdaptersInfo?

  • Lovelina

    Pls refer to following link for more appropriate forums for this topic

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=286724&SiteID=1

    Srikanth Bogadapati



  • JVidal

    How do you allocate the memory for the ID_ADAPTER_INFO structure Can you share the complete code where you have "..." above in the code sample

    -Devidas


  • ado79229

    Thanks for the reply. The "..." part doesn't seem to matter. As an experiment, I looped the following code several thousand times:

    for( int i=0; i < 5000; i++ )
    {
    IP_ADAPTER_INFO* aInfo = 0;
    ULONG sz = 0;
    DWORD res = GetAdaptersInfo(aInfo, &sz);
    delete [] adapterInfo;
    }


    I used GlobalMemoryStatus(&memInfo) to see the current memory during the process and after many loops, I can see the memory getting bumped up a bit at a time ( 4096 bytes ). Also there is no telling how long it takes for memory to increase. It just does it after some random iteration.

  • analog Tv

    I revised the code to the following:

    for( int i = 0; i < 20000; i++ )
    {
    ULONG ulOutBufLen;
    DWORD dwRetVal;
    IP_ADAPTER_INFO *pAdapterInfo;
    ulOutBufLen = 0;

    //Call GetAdaptersInfo to get the size of the buffer
    GetAdaptersInfo( NULL, &ulOutBufLen) ;

    //Now that we know the necessary buffer size, allocate the memory
    pAdapterInfo = (IP_ADAPTER_INFO *) malloc( ulOutBufLen );

    dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen);

    if (pAdapterInfo)
    free(pAdapterInfo);
    }

    However I still get memory loss running this function. I also want to note that this only happens on the Samsung i730 (WinCE 4.2). When I try this exact code on a WM5 device I don't see the memory loss.

  • Maxim Aniskov

    It seems you allways delete the adapterInfo but it should only be deleted if it is realy used. If you call GetAdaptersInfo with size 0 it wil return how large the block of memory should be. This wil be stored inside sz.
    Calling GetAdaptersInfo with a valid pointer to a memory block will allow you to delete the buffer. Here is how it should be used:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/iphlp/iphlp/getadaptersinfo.asp

    And here is the original Windows CE 5.0 example:


    http://msdn.microsoft.com/library/default.asp url=/library/en-us/wcecomm5/html/wce51concompleteiphelperapplicationsourcecode.asp


  • Memory problem using GetAdaptersInfo?