To tylko jedna z 2 stron tej notatki. Zaloguj się aby zobaczyć ten dokument.
Zobacz
całą notatkę
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)