-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEX08a_arrays.cpp
57 lines (55 loc) · 2 KB
/
EX08a_arrays.cpp
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
// Für DOS
#include <iostream> // for using cout
#include <malloc.h> // for using malloc_usable_size
using namespace std;
int main()
{
//----------------------------------------------------------------
cout << "EX08a Arrays: Memory allocation and release" << endl;
cout << ".....................\n";
//----------------------------------------------------------------
// Definitions
cout << "Speicherbedarf Zeiger\n";
char* Zeichenkette;
int* iVektor;
double* dVektor;
cout << "Zeichenkette:\t" << sizeof(Zeichenkette) << "\n";
cout << "iVektor:\t" << sizeof(iVektor) << "\n";
cout << "dVektor:\t" << sizeof(dVektor) << "\n";
cout << ".....................\n";
//----------------------------------------------------------------
// Memory allocation
cout << "Speicherbedarf Arrays\n";
Zeichenkette = new char[100000];
iVektor = new int[100000];
dVektor = new double[100000];
long size_memory;
size_memory = _msize(Zeichenkette);
// size_memory = malloc_usable_size(Zeichenkette);
cout << "Zeichenkette:\t" << size_memory << "\n";
size_memory = _msize(iVektor);
cout << "iVektor:\t" << size_memory << "\n";
size_memory = _msize(dVektor);
cout << "dVektor:\t" << size_memory << "\n";
cout << ".....................\n";
//----------------------------------------------------------------
cout << "Speicherfreigabe\n";
delete [] Zeichenkette;
Zeichenkette = NULL;
delete [] iVektor;
iVektor = NULL;
delete [] dVektor;
dVektor = NULL;
size_memory = _msize(Zeichenkette);
cout << "Zeichenkette:\t" << size_memory << "\n";
size_memory = _msize(iVektor);
cout << "iVektor:\t" << size_memory << "\n";
size_memory = _msize(dVektor);
cout << "dVektor:\t" << size_memory << "\n";
cout << "....................\n";
//----------------------------------------------------------------
dVektor = new double[200000000];
size_memory = _msize(dVektor);
cout << "dVektor:\t" << size_memory << "\n";
return 0;
}