visual c++ - Memory management with HEAP arrays -


if create heap array inside loop, have delete @ end of each loop before reinitialize @ beginning of loop again or reinitializing exact same thing again overwrite old array , can skip delete command?

do mean this?

for (int = 0; < 5; i++) {     char *array = new char[10];     // ...     delete[] array; } 

in case: yes, need delete array.

if had written instead,

char *array = 0; (int = 0; < 5; i++) {     if (!array) array = new char[10];     // ... } delete[] array; 

then no, can reuse array across multiple iterations of loop.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -