Flob
3
Q:

delete memory c++

// Delete pointer
int* ptr1 = new int;
delete ptr1;

// Delete array
int* array = new int[10];
delete[] array;  
4
// Release block of memory 
// pointed by pointer-variable
delete[] pointer-variable;  

Example:
   // It will free the entire array
   // pointed by p.
   delete[] p;
1
//placement new in c++
char *buf  = new char[sizeof(string)]; // pre-allocated buffer
string *p = new (buf) string("hi");    // placement new
string *q = new string("hi");          // ordinary heap allocation
/*Standard C++ also supports placement new operator, which constructs 
an object on a pre-allocated buffer. This is useful when building a 
memory pool, a garbage collector or simply when performance and exception 
safety are paramount (there's no danger of allocation failure since the memory
has already been allocated, and constructing an object on a pre-allocated
buffer takes less time):
*/
0

New to Communities?

Join the community