"const char * name", is the name be deleted ?
Printable View
"const char * name", is the name be deleted ?
I am not sure whether I understood correctly...but it depends:
- You need to delete
Code:char *p = new char[100];
// Do something with 'p'
delete [] p;
- You do not need to delete
Code:const char *p = "Hello World";
[Edited]: Messed up a little bit on the first example...corrected... :cool:
if you dont use "delete" to free point,
how to free the point?
i'm not sure what you're saying here, but:Quote:
Originally posted by herofyf
if you dont use "delete" to free point,
how to free the point?
what is newed must be deleted, what is not it doesn't. as simple as that.
as title!
In C++,If you use new to dynamically allocate memory, you must use delete to dealocate memory, return what you have taken to its owner. Then the freed memory may be recycled by being used for subsequent allocation, or by being returned to the operating system.Quote:
Originally posted by herofyf
if you dont use "delete" to free point,
how to free the point?
In C, If you use malloc, then free is what you must use.
In some cases where you implement your own "delete" and "new" especially as I see in patterns for memory management, these malloc and free are still being used very oftenly, even in C++ environment.
I think there is no way to accomplish what you are wanting as being said in your post I quoted.
It is just like if you buy something, you must pay money(by yens/dollars...).., you cannot pay them your memos, writing papers etc, right ? :D
Regards,
-Vu