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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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