Bonjour,
je me suis amusé a faire une bête liste chainée et je ne comprends pas pourquoi mon programme prends près de 4 Mo à la fin de l'exécution par rapport au 310 ko de départ.

Si j'appelle ma fonction plusieurs fois, à la fin mon programme prends environ 4,4Mo

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
#include <stdio.h>
#include <stdlib.h>
 
struct pchar
{
    char caract;
    struct pchar *nextChar;
}pchar;
 
typedef struct pchar* tpchar;
 
void mumuse ()
{
    tpchar testmem;
    tpchar temp;
    tpchar tete_liste;
    int i;
    printf ("je vais prendre de la memoire\n");
    scanf ("%d", &i );
    testmem = ( tpchar ) malloc ( sizeof ( pchar ));
    tete_liste = testmem;
    for ( i = 0 ; i <= 30000000 ; i++ )
    {
        testmem -> nextChar = ( tpchar ) malloc ( sizeof ( pchar ));
        testmem = testmem -> nextChar;
    }
    testmem -> nextChar = NULL;
    printf ("la mémoire est prise\n");
    scanf ("%d", &i );
    testmem = tete_liste;
    while ( testmem != NULL )
    {
        temp = testmem;
        testmem = testmem -> nextChar;
        free(temp);
    }
    printf ("il reste 3 mo...\n", &i );
    scanf ("%d", &i );
}
int main(void)
{
    int i;
    mumuse ();
    scanf ("%d", &i );
    return 0;
}