|
-
January 30th, 2004, 01:50 AM
#1
about delete
"const char * name", is the name be deleted ?
-
January 30th, 2004, 02:10 AM
#2
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...
Last edited by Andreas Masur; January 30th, 2004 at 04:38 PM.
-
January 30th, 2004, 02:19 AM
#3
why?
if you dont use "delete" to free point,
how to free the point?
-
January 30th, 2004, 02:24 AM
#4
Re: why?
Originally posted by herofyf
if you dont use "delete" to free point,
how to free the point?
i'm not sure what you're saying here, but:
what is newed must be deleted, what is not it doesn't. as simple as that.
-
January 30th, 2004, 03:11 AM
#5
-
January 30th, 2004, 05:00 AM
#6
Re: why?
Originally posted by herofyf
if you dont use "delete" to free point,
how to free the point?
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.
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 ? 
Regards,
-Vu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|