First look at a blog about class creation objects: http://www.cnblogs.com/xumenger/p/4462975.html
Lenovo to allocate memory through pointers
After we have dynamically allocated memory through pointers, we need to remember this pointer (which points to the allocated memory), such as the
int *pi;pi = (int*) malloc (10* sizeof (int));
PI is the address used to record the allocated memory. In Delphi
var pi:pinteger;begin Getmem (p, sizeof (Integer) *10); end;
The pi here is also used to record the allocated memory address
As in both cases, if you want PI to point to the new address before releasing the memory, be sure to create a new pointer to hold the value of the Pi first (that is, the address that holds the memory, such as Ptemp)
int* ptemp = pi;//delphi var ptemp:pinteger;begin ptemp:= Pi;end in C + + ;
Then let the pi point to the new address, so that it is not to lose control of the memory, so that pi no longer points to the memory, but you can use a new pointer to the memory of the memory to release the RAM, not the memory leaks, such as in C + + and Delphi
Free (ptemp),//delphi Freemem (ptemp);
Why do you remember the address of this memory?
Because you need to allocate this memory to use this memory to store data, manipulate the data here, and eventually release the memory.
Only you record the address of this memory, you can use this memory through pointers, and finally can release the memory, otherwise the memory of the horse lost the memory of the address, on the one hand cannot use this memory, on the other hand can not free memory, resulting in memory leaks
According to the previous blog, I think of the memory allocation and management problems of C/C + + and Delphi.