Having structures like
struct ifoo_version_42 { int x, y, z; char *imageData; };
where imageDatais something likeimageData = new char[50000];
imageData
imageData = new char[50000];
Can we do something like:
template< typename T > void del( T a ) // we promise to use this only on C Plain Old data structs=) { delete a; }
in this structure will be enough to clear the shape of the memory if?
Deleting a structure does not recursively delete any pointers in it and therefore does not free the char array that it points to imageData.
delete[]. ( new[]) delete[] ( new) delete. , , ifoo_version_42. , undefined:
delete[]
new[]
new
delete
ifoo_version_42
ifoo_version_42 *x = new ifoo_version_42; del(x);
:
ifoo_version_42 *x = new ifoo_version_42[1]; del(x);
"" -POD-. delete[] a;.
delete[] a;
, imageData. , .
del ifoo_version_42, , data, ; delete, delete[] .
del
data
delete[] arrays; , imageData new[], delete[].
arrays
delete : , , ifoo_version_42 new, delete.
( , delete - malloc() free() -, new.)
malloc()
free()
: RAII , STL Boost; .
Source: https://habr.com/ru/post/1787278/More articles:Wine tasting problem - algorithmEclipse Java EE: when starting the application, stop the old executable instance - javaDoes the use of explicit / explicit conversion operators violate the single responsibility pattern in favor of DRY? - architecture'>' sign in class definition - cssHow to determine if we need to learn another javascript library? - jquerypython: представляет квадратную сетку, которая обертывается на себя (цилиндр) - pythonИзменение WPF RadioButton не обновляет пользовательский интерфейс MVVM - wpfNews Articles: Writing to a server without PHP? - javafacebook as ajax in yii zii widget list - ajaxConverting a sum to an aggregated product expression - c #All Articles