Reallocation
-
-
Is it possible to reallocate using operator new? // C some_ptr = malloc( sizeof( some_type ) * n ); ... // change "n" some_ptr = realloc( sizeof( some_type ) * n ); // C++ some_ptr = new some_type[n]; ... // change "n" // Now what? Best regards hint_54
The short answer is no. Either use a combination of malloc and realloc as in your example, or use the keyword new and copy the contents over to a larger buffer.
-
The short answer is no. Either use a combination of malloc and realloc as in your example, or use the keyword new and copy the contents over to a larger buffer.
-
Is it possible to reallocate using operator new? // C some_ptr = malloc( sizeof( some_type ) * n ); ... // change "n" some_ptr = realloc( sizeof( some_type ) * n ); // C++ some_ptr = new some_type[n]; ... // change "n" // Now what? Best regards hint_54
Use an STL collection such as
vector
, and you won't have to worry about the memory allocation.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ