.\" -*- coding: UTF-8 -*- '\" t .\" Copyright (c) 2012 by Michael Kerrisk .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH malloc_info 3 "20 juillet 2023" "Pages du manuel de Linux 6.05.01" .SH NOM malloc_info \- Exporter l'état de malloc vers un flux .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP, \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .PP \fBint malloc_info(int \fP\fIoptions\fP\fB, FILE *\fP\fIstream\fP\fB);\fP .fi .SH DESCRIPTION La fonction \fBmalloc_info\fP() exporte une chaîne XML décrivant l'état actuel de l'allocation mémoire pour l'appelant. Cette chaîne est écrite dans le flux \fIstream\fP. La chaîne exportée contient des informations concernant toutes les domaines de mémoires («\ arenas\ », consultez \fBmalloc\fP(3)). .PP Dans la mise en œuvre actuelle, le paramètre \fIoptions\fP doit être nul. .SH "VALEUR RENVOYÉE" En cas de succès, \fBmalloc_info\fP() renvoie \fB0\fP. En cas d'erreur, \fB\-1\fP est renvoyé et \fIerrno\fP contient le code d'erreur. .SH ERREURS .TP \fBEINVAL\fP Le paramètre \fIoptions\fP n'était pas nul. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Interface Attribut Valeur T{ .na .nh \fBmalloc_info\fP() T} Sécurité des threads MT\-Safe .TE .sp 1 .SH STANDARDS GNU. .SH HISTORIQUE glibc 2.10. .SH NOTES L'information d'allocation mémoire est fournie sous forme de flux XML (plutôt que de structure\ C), car les informations fournies pourront évoluer dans le futur, en raison de modifications dans le code mis en œuvre. La sortie XML comporte un champ de version. .PP La fonction \fBopen_memstream\fP(3) peut être utilisée pour envoyer la sortie de \fBmalloc_info\fP() directement dans un tampon en mémoire plutôt que dans un fichier. .PP La fonction \fBmalloc_info\fP() est conçue pour combler les manques de \fBmalloc_stats\fP(3) et \fBmallinfo\fP(3). .SH EXEMPLES Le programme ci\-dessous accepte jusqu'à quatre paramètres en ligne de commande dont les trois premiers sont obligatoires. Le premier paramètre indique le nombre de processus légers («\ threads\ ») que le programme doit créer. Tous les threads, thread principal compris, allouent le nombre de blocs de mémoire indiqué en deuxième paramètre. Le troisième paramètre contrôle la taille des blocs à allouer. Le thread principal crée des blocs de cette taille, le deuxième thread créé par le programme alloue des blocs deux fois plus grands, le troisième thread alloue des blocs trois fois plus grands et ainsi de suite. .PP Le programme appelle \fBmalloc_info\fP() deux fois pour afficher l'état de l'allocation mémoire. Le premier appel est effectué avant la création d’un thread ou l'allocation de mémoire. Le deuxième appel est effectué une fois que tous les threads ont alloué de la mémoire. .PP Dans l'exemple suivant, les paramètres commandent la création d'un thread additionnel, allouant 10\ 000\ blocs de mémoire, comme le thread principal. Une fois les blocs de mémoire alloués, \fBmalloc_info\fP() affiche l'état des deux domaines de mémoire. .PP .in +4n .EX $ \fBgetconf GNU_LIBC_VERSION\fP glibc 2.13 $ \fB./a.out 1 10000 100\fP ============ Before allocating blocks ============ \& ============ After allocating blocks ============ .EE .in .SS "Source du programme" .\" SRC BEGIN (malloc_info.c) .EX #include #include #include #include #include #include \& static size_t blockSize; static size_t numThreads; static unsigned int numBlocks; \& static void * thread_func(void *arg) { int tn = (int) arg; \& /* The multiplier \[aq](2 + tn)\[aq] ensures that each thread (including the main thread) allocates a different amount of memory. */ \& for (unsigned int j = 0; j < numBlocks; j++) if (malloc(blockSize * (2 + tn)) == NULL) err(EXIT_FAILURE, "malloc\-thread"); \& sleep(100); /* Sleep until main thread terminates. */ return NULL; } \& int main(int argc, char *argv[]) { int sleepTime; pthread_t *thr; \& if (argc < 4) { fprintf(stderr, "%s num\-threads num\-blocks block\-size [sleep\-time]\en", argv[0]); exit(EXIT_FAILURE); } \& numThreads = atoi(argv[1]); numBlocks = atoi(argv[2]); blockSize = atoi(argv[3]); sleepTime = (argc > 4) ? atoi(argv[4]) : 0; \& thr = calloc(numThreads, sizeof(*thr)); if (thr == NULL) err(EXIT_FAILURE, "calloc"); \& printf("============ Before allocating blocks ============\en"); malloc_info(0, stdout); \& /* Create threads that allocate different amounts of memory. */ \& for (size_t tn = 0; tn < numThreads; tn++) { errno = pthread_create(&thr[tn], NULL, thread_func, (void *) tn); if (errno != 0) err(EXIT_FAILURE, "pthread_create"); \& /* If we add a sleep interval after the start\-up of each thread, the threads likely won\[aq]t contend for malloc mutexes, and therefore additional arenas won\[aq]t be allocated (see malloc(3)). */ \& if (sleepTime > 0) sleep(sleepTime); } \& /* The main thread also allocates some memory. */ \& for (unsigned int j = 0; j < numBlocks; j++) if (malloc(blockSize) == NULL) err(EXIT_FAILURE, "malloc"); \& sleep(2); /* Give all threads a chance to complete allocations. */ \& printf("\en============ After allocating blocks ============\en"); malloc_info(0, stdout); \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VOIR AUSSI" \fBmallinfo\fP(3), \fBmalloc\fP(3), \fBmalloc_stats\fP(3), \fBmallopt\fP(3), \fBopen_memstream\fP(3) .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot et Grégoire Scano . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .