Bonjour,
Quelqu'un pourait'il me dire que coûte en mémoire une variable de type CString et comment évolue t'elle en fonction du nombre de caratères?
Merci
Version imprimable
Bonjour,
Quelqu'un pourait'il me dire que coûte en mémoire une variable de type CString et comment évolue t'elle en fonction du nombre de caratères?
Merci
salut,
difficile de répondre, déjà la réponse sera différente pour visual 6.0 et visual 2005.
ce dernier utilisant la SL.
le cout est égal a la chaine en mémoire + les données membres permettant la gestion de l'objet.
c'est cette derniere partie qui est difficile a évaluer sauf peut ête a utiliser une fonction comme GlobalMemoryStatus avant et apres l'allocation de l'objet.
Code:
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
48
49
50
51
52 // Sample output: // The MemoryStatus structure is 32 bytes long. // It should be 32. // 78 percent of memory is in use. // There are 65076 total Kbytes of physical memory. // There are 13756 free Kbytes of physical memory. // There are 150960 total Kbytes of paging file. // There are 87816 free Kbytes of paging file. // There are 1fff80 total Kbytes of virtual memory. // There are 1fe770 free Kbytes of virtual memory. #include <windows.h> // Use to change the divisor from Kb to Mb. #define DIV 1024 // #define DIV 1 char *divisor = "K"; // char *divisor = ""; // Handle the width of the field in which to print numbers this way to // make changes easier. The asterisk in the print format specifier // "%*ld" takes an int from the argument list, and uses it to pad and // right-justify the number being formatted. #define WIDTH 7 void main(int argc, char *argv[]) { MEMORYSTATUS stat; GlobalMemoryStatus (&stat); printf ("The MemoryStatus structure is %ld bytes long.\n", stat.dwLength); printf ("It should be %d.\n", sizeof (stat)); printf ("%ld percent of memory is in use.\n", stat.dwMemoryLoad); printf ("There are %*ld total %sbytes of physical memory.\n", WIDTH, stat.dwTotalPhys/DIV, divisor); printf ("There are %*ld free %sbytes of physical memory.\n", WIDTH, stat.dwAvailPhys/DIV, divisor); printf ("There are %*ld total %sbytes of paging file.\n", WIDTH, stat.dwTotalPageFile/DIV, divisor); printf ("There are %*ld free %sbytes of paging file.\n", WIDTH, stat.dwAvailPageFile/DIV, divisor); printf ("There are %*lx total %sbytes of virtual memory.\n", WIDTH, stat.dwTotalVirtual/DIV, divisor); printf ("There are %*lx free %sbytes of virtual memory.\n", WIDTH, stat.dwAvailVirtual/DIV, divisor); }