Reallocating Memory Allocated By new
In contrast to C's realloc
, it is not possible to directly reallocate memory allocated with new
. To extend or reduce the size of a block, one must allocate a new block of adequate size, copy over the old memory, and delete the old block. The C++ standard library provides a dynamic array that can be extended or reduced in its std::vector
template.
Read more about this topic: New (C++)
Famous quotes containing the word memory:
“A man is the prisoner of his power. A topical memory makes him an almanac; a talent for debate, disputant; skill to get money makes him a miser, that is, a beggar. Culture reduces these inflammations by invoking the aid of other powers against the dominant talent, and by appealing to the rank of powers. It watches success.”
—Ralph Waldo Emerson (18031882)