kennen:lib:free
no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
— | kennen:lib:free [2019-11-20 16:06] (aktuell) – angelegt - Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== free() ====== | ||
+ | ''# | ||
+ | |||
+ | <code cpp> | ||
+ | void free (void *ptr) | ||
+ | </ | ||
+ | Gibt durch | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | ==== Parameter ==== | ||
+ | | '' | ||
+ | |||
+ | Vorsicht, Gefahrenquellen: | ||
+ | |||
+ | - Nichtfreigeben führt zu Speicherlecks. | ||
+ | - Mehrmaliges Freigeben führt zu unkontrollierbarem Verhalten (Speicherkonfusion, | ||
+ | - Laut Standard ISO C 9899:1999 ist der Aufruf mit dem Argumentwert '' | ||
+ | - Mit [[..: | ||
+ | ==== Ergebnis ==== | ||
+ | Rückgabewert: | ||
+ | Der '' | ||
+ | |||
+ | ==== Siehe auch ==== | ||
+ | Operatoren [[..: | ||
+ | [[calloc]], | ||
+ | [[malloc]], | ||
+ | [[realloc]]. | ||
+ | |||
+ | ==== Beispiel ==== | ||
+ | <code cpp free.cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | using namespace std; | ||
+ | int anzahl = 1000; | ||
+ | int *ptr = (int*) malloc(anzahl*sizeof(int)); | ||
+ | |||
+ | if (ptr != NULL) | ||
+ | { | ||
+ | ptr[0] = 0; | ||
+ | ptr[anzahl-1] = 999; | ||
+ | // ... | ||
+ | cout << ptr[0] << " | ||
+ | free(ptr); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | cerr << "Nicht genug Speicher vorhanden.\n"; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
kennen/lib/free.txt · Zuletzt geändert: 2019-11-20 16:06 von 127.0.0.1