voici le code qui est la cause de mes maux de tête .. depuis 3 jours.
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 #include <fstream> #include <iostream> #include <memory> using namespace std; class file_error {}; class entier_f { private: int * a; char * fn; ifstream input; public: entier_f(char * nom, int val=0) : fn(nom) { a = new int[1000000]; // Allocation d'un tableau de 1 Mo !!! *a= val; input.open(fn); if (! input) { throw(file_error()); }; }; ~entier_f() { delete a; a=NULL; input.close(); }; }; class entier_f1 { private: auto_ptr<int> a; char * fn; ifstream input; public: entier_f1(char * nom, int val=0) : fn(nom) { a = new int[1000000]; // Allocation d'un tableau de 1 Mo !!! *a= val; input.open(fn); if (! input) { throw(file_error()); }; }; ~entier_f1() { input.close(); }; }; main() { try { entier_f I2("toto"); } catch(file_error) { cout << "erreur de lecture de fichier" << endl; }; int j=0; for (int i=0;i<100;i++) { j++; try { entier_f1 I2("toto"); } catch (file_error) { // cout << "ERR" << endl; continue; } catch (...) { break; // Pas de fuite de memoire }; }; cout << "boucle executee " << j << " fois" << endl; j=0; for (int i=0;i<100;i++) { j++; try { entier_f I2("toto"); } catch (file_error) { // cout << "ERR" << endl; continue; } catch (...) { break; // ca va planter (fuite de memoire) }; }; cout << "boucle executee " << j << " fois" << endl; };
Partager