Memory management

Nasza ocena:

3
Pobrań: 14
Wyświetleń: 644
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
Memory management - strona 1 Memory management - strona 2

Fragment notatki:

Memory management  allocating memory: operator new  syntax: new Type  example: int * pi = new int; // in C: pi = (int*)malloc(sizeof(int))  deallocating: operator delete  syntax: delete pointer  example: delete pi; // does not change pi  Allocating arrays int * pai = new int [num_of_elem]; delete [] pai;  In new compilers [] are not necessary  multidimensional arrays int *pmulti = new int[n][5][10] // all dimensions, but the first one have to // be known at the compilation time delete [] pmulti;  A function may be defined to be called in case of failed memory allocation: set_new_handler(); //  otherwise unsuccessful new returns NULL (0)  delete NULL does nothing  do not mix new/delete with malloc/free

(…)


Memory management
 allocating memory: operator new
 syntax:
new Type
 example:
int * pi = new int; // in C: pi = (int*)malloc(sizeof(int))
 deallocating: operator delete
 syntax:
delete pointer
 example:
delete pi; // does not change pi
 Allocating arrays
int * pai = new int [num_of_elem];
delete [] pai;
 In new compilers [] are not necessary
 multidimensional arrays
int *pmulti = new…
... zobacz całą notatkę

Komentarze użytkowników (0)

Zaloguj się, aby dodać komentarz