src/gc/windows/gcenv.windows.cpp
SYSTEM_LOGICAL_PROCESSOR_INFORMATION *GetLPI(PDWORD nEntries) 
{
    DWORD cbslpi = 0;
    DWORD dwNumElements = 0;
    SYSTEM_LOGICAL_PROCESSOR_INFORMATION *pslpi = NULL;

    // We setup the first call to GetLogicalProcessorInformation to fail so that we can obtain
    // the size of the buffer required to allocate for the SLPI array that is returned

    if (!GetLogicalProcessorInformation(pslpi, &cbslpi) &&
            GetLastError() != ERROR_INSUFFICIENT_BUFFER)
    {
        // If we fail with anything other than an ERROR_INSUFFICIENT_BUFFER here, we punt with failure.
        return NULL;
    }

    _ASSERTE(cbslpi);

    // compute the number of SLPI entries required to hold the information returned from GLPI

    dwNumElements = cbslpi / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);

    // allocate a buffer in the free heap to hold an array of SLPI entries from GLPI, number of elements in the array is dwNumElements 

    pslpi = new (std::nothrow) SYSTEM_LOGICAL_PROCESSOR_INFORMATION[ dwNumElements ];

    if (pslpi == NULL)
    {
        // the memory allocation failed
        return NULL;
    }      

    // Make call to GetLogicalProcessorInformation. Returns array of SLPI structures

    if (!GetLogicalProcessorInformation(pslpi, &cbslpi))
    {
        // GetLogicalProcessorInformation failed
        delete[] pslpi ; //Allocation was fine but the API call itself failed and so we are releasing the memory before the return NULL.
        return NULL ;
    } 

    // GetLogicalProcessorInformation successful, set nEntries to number of entries in the SLPI array
    *nEntries  = dwNumElements;

    return pslpi;    // return pointer to SLPI array

}
// This function checks to see if GetLogicalProcessorInformation API is supported. 
// On success, this function allocates a SLPI array, sets nEntries to number 
// of elements in the SLPI array and returns a pointer to the SLPI array after filling it with information. 
//
// Note: If successful, GetLPI allocates memory for the SLPI array and expects the caller to
// free the memory once the caller is done using the information in the SLPI array.
This function checks to see if GetLogicalProcessorInformation API is supported.
On success, this function allocates a SLPI array, sets nEntries to number
of elements in the SLPI array and returns a pointer to the SLPI array after filling it with information.

If successful, GetLPI allocates memory for the SLPI array and expects the caller to
free the memory once the caller is done using the information in the SLPI array.
This function checks to see if GetLogicalProcessorInformation API is supported . On success this function allocates a SLPI array sets nEntries to number of elements in the SLPI array and returns a pointer to the SLPI array after filling it with information . If successful GetLPI allocates memory for the SLPI array and expects the caller to free the memory once the caller is done using the information in the SLPI array .
SYSTEM_LOGICAL_PROCESSOR_INFORMATION *GetLPI(PDWORD nEntries) 
{
    DWORD cbslpi = 0;
    DWORD dwNumElements = 0;
    SYSTEM_LOGICAL_PROCESSOR_INFORMATION *pslpi = NULL;
    if (!GetLogicalProcessorInformation(pslpi, &cbslpi) &&
            GetLastError() != ERROR_INSUFFICIENT_BUFFER)
    {
        return NULL;
    }
    _ASSERTE(cbslpi);
    dwNumElements = cbslpi / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
    pslpi = new (std::nothrow) SYSTEM_LOGICAL_PROCESSOR_INFORMATION[ dwNumElements ];
    if (pslpi == NULL)
    {
        return NULL;
    }      
    if (!GetLogicalProcessorInformation(pslpi, &cbslpi))
    {
        delete[] pslpi ; 
        return NULL ;
    } 
    *nEntries  = dwNumElements;
    return pslpi;    
}
SYSTEM_LOGICAL_PROCESSOR_INFORMATION * GetLPI ( PDWORD nEntries ) { DWORD cbslpi = 0 ; DWORD dwNumElements = 0 ; SYSTEM_LOGICAL_PROCESSOR_INFORMATION * pslpi = NULL ; if ( ! GetLogicalProcessorInformation ( pslpi , & cbslpi ) && GetLastError ( ) != ERROR_INSUFFICIENT_BUFFER ) { return NULL ; } _ASSERTE ( cbslpi ) ; dwNumElements = cbslpi / sizeof ( SYSTEM_LOGICAL_PROCESSOR_INFORMATION ) ; pslpi = new ( std :: nothrow ) SYSTEM_LOGICAL_PROCESSOR_INFORMATION [ dwNumElements ] ; if ( pslpi == NULL ) { return NULL ; } if ( ! GetLogicalProcessorInformation ( pslpi , & cbslpi ) ) { delete [ ] pslpi ; return NULL ; } * nEntries = dwNumElements ; return pslpi ; }
This function checks to see if GetLogicalProcessorInformation API is supported.
This function checks to see if GetLogicalProcessorInformation API is supported .
// We setup the first call to GetLogicalProcessorInformation to fail so that we can obtain // the size of the buffer required to allocate for the SLPI array that is returned // If we fail with anything other than an ERROR_INSUFFICIENT_BUFFER here, we punt with failure. // compute the number of SLPI entries required to hold the information returned from GLPI // allocate a buffer in the free heap to hold an array of SLPI entries from GLPI, number of elements in the array is dwNumElements  // the memory allocation failed // Make call to GetLogicalProcessorInformation. Returns array of SLPI structures // GetLogicalProcessorInformation failed //Allocation was fine but the API call itself failed and so we are releasing the memory before the return NULL. // GetLogicalProcessorInformation successful, set nEntries to number of entries in the SLPI array // return pointer to SLPI array