realloc
Aus cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
definiert in Header <stdlib.h>
|
||
void *realloc( void *ptr, size_t new_size ); |
||
Weist einen Speicherbereich neu zu, wobei es durch Angabe der neuen Wunschgröße
new_size
möglich ist, einen genutzten Speicherbereich zu verkleinern oder zu vergrößern. Der Speicherbereich muss vorher schon einmal durch malloc()
, calloc()
oder realloc()
zugewiesen worden und noch nicht mit free()
freigegeben sein; anderenfalls ist das Ergebnis undefiniert.Original:
Reallocates the given area of memory. It must be previously allocated by
malloc()
, calloc()
or realloc()
and not yet freed with free()
, otherwise, the results are undefined.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Die Neuzuweisung erfolgt durch entweder:
Original:
The reallocation is done by either:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
a)
Erweiterung des bestehenden Bereiches, auf den
ptr
zeigt - falls das möglich ist. Die Inhalte des Bereichs bleiben so weit wie möglich unverändert. Falls also der Speicherbereich verkleinert wird, bleibt er bis zur neuen, kleineren Grenze unverändert. Bei Vergrößerung/Erweiterung ist der alte Speicherbereich unverändert; der Inhalt des neuen Bereiches ist nicht definiert. Original:
expanding the existing area pointed to by
ptr
, if possible. The contents of the area remain unchanged up to the lesser of the new and old sizes. If the area is expanded, the contents of the new part of the array are undefined. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
b)
Zuweisung eines völlig neuen Speicherblock der gewünschten Größe
new_size
Bytes, anschließendem Kopieren des alten Speicherbereichs in den neuen und abschließender Freigabe den alten Speicherblocks.Original:
allocating a new memory block of size
new_size
bytes, copying memory area with size equal the lesser of the new and the old sizes, and freeing the old block.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Wenn es nicht genügend Speicher zur Verfügung steht, wird der alte Speicherblock nicht freigegeben und Null-Pointer zurückgegeben .
Original:
If there is not enough memory, the old memory block is not freed and null-pointer is returned.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Inhaltsverzeichnis |
[Bearbeiten] Parameter
ptr | - | Zeiger auf den Speicherbereich neu zugeteilt werden
Original: pointer to the memory area to be reallocated The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
new_size | - | neue Größe des Arrays
Original: new size of the array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[Bearbeiten] Rückgabewert
Zeiger auf den Beginn des neu zugewiesenen Speicher oder NULL, wenn Fehler aufgetreten ist. Der Zeiger muss mit
free()
freigegeben werden .Original:
Pointer to the beginning of newly allocated memory or NULL if error has occurred. The pointer must be deallocated with
free()
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Beispiel
This section is incomplete Reason: no example |
[Bearbeiten] Siehe auch
C++ documentation for realloc
|