_CrtIsValidHeapPointer

Vérifie qu'un pointeur spécifié est dans le tas local (version debug uniquement).

int _CrtIsValidHeapPointer( 
   const void *userData 
);

Paramètres

  • userData
    Pointeur vers le début d'un bloc de mémoire alloué.

Valeur de retour

retourne TRUE d'_CrtIsValidHeapPointer si le pointeur est spécifié dans le tas local.Sinon, la fonction retourne FALSE.

Notes

la fonction d' _CrtIsValidHeapPointer est utilisée pour garantir qu'une adresse mémoire spécifique est dans le tas local.Le tas local fait référence au tas créé et géré par une instance particulière de la bibliothèque Runtime C.Si une bibliothèque de (DLL) liens dynamiques contient un lien statique vers la bibliothèque Runtime, elle possède sa propre instance du tas au moment de l'exécution, et par conséquent son propre le tas, indépendamment du tas local de l'application.Lorsque _DEBUG n'est pas défini, les appels à _CrtIsValidHeapPointer sont supprimés pendant le prétraitement.

Étant donné que cette fonction retourne TRUE ou FALSE, elle peut être passée à l'une des macros de _ASSERT créer un mécanisme simple de gestion des erreurs d'erreur de débogage.L'exemple suivant crée un échec d'assertion si l'adresse spécifiée ne se trouve pas dans le tas local :

_ASSERTE( _CrtIsValidHeapPointer( userData ) );

Pour plus d'informations sur la façon dont _CrtIsValidHeapPointer peut être utilisé avec d'autres fonctions et des macros de débogage, consultez À l'aide de les macros pour la vérification et la création de rapports.Pour plus d'informations sur la manière dont les blocs de mémoire sont alloués, initialisés, et gérés dans la version debug de tas de base, consultez gestion de la mémoire et le tas de débogage.

Configuration requise

routine

en-tête requis

_CrtIsValidHeapPointer

<crtdbg.h>

Pour plus d'informations de compatibilité, consultez compatibilité dans l'introduction.

bibliothèques

Versions debug de Bibliothèques runtime C uniquement.

Exemple

// crt_isvalid.c
/*
 * This program allocates a block of memory using _malloc_dbg
 * and then tests the validity of this memory by calling 
 * _CrtIsMemoryBlock,_CrtIsValidPointer, and _CrtIsValidHeapPointer.
 */

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <crtdbg.h>

#define  TRUE   1
#define  FALSE  0

int main( void )
{
        char *my_pointer;

        /* 
         * Call _malloc_dbg to include the filename and line number
         * of our allocation request in the header information
         */
        my_pointer = (char *)_malloc_dbg( sizeof(char) * 10, 
        _NORMAL_BLOCK, __FILE__, __LINE__ );

        // Ensure that the memory got allocated correctly
        _CrtIsMemoryBlock((const void *)my_pointer, sizeof(char) * 10, 
        NULL, NULL, NULL );

         // Test for read/write accessibility
        if (_CrtIsValidPointer((const void *)my_pointer, 
        sizeof(char) * 10, TRUE))
                printf("my_pointer has read and write accessibility.\n");
        else
                printf("my_pointer only has read access.\n");

        // Make sure my_pointer is within the local heap
        if (_CrtIsValidHeapPointer((const void *)my_pointer))
                printf("my_pointer is within the local heap.\n");
        else
                printf("my_pointer is not located within the local"
                       " heap.\n");

        free(my_pointer);
}

Sortie

my_pointer has read and write accessibility.
my_pointer is within the local heap.

Équivalent .NET Framework

Non applicable. Pour appeler la fonction C standard, utilisez PInvoke. Pour plus d'informations, consultez l' exemples d'appel de code non managé.

Voir aussi

Référence

Déboguez des routines