F
Frederick Gotham
Sekhar posted:
(I'm going to use "malloc" in this example just to try to make it easier
to understand.)
Here is a normal use of "new":
Type *p = new Type;
This does two things:
(1) It allocates memory.
(2) It constructs an object at that location in memory.
Here is a special use of "new" called "placement new":
Type *p = malloc( sizeof(Type) ); /* This only allocates memory */
::new(p) Type; /* This constructs an object at the address
specified by "p" */
For info on "placement new", try this:
http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10
Thanks for making concepts more clear. This code snippet gives me
more thoughts on new operator. Can you just breif on how new operator
works on the above statement.
(I'm going to use "malloc" in this example just to try to make it easier
to understand.)
Here is a normal use of "new":
Type *p = new Type;
This does two things:
(1) It allocates memory.
(2) It constructs an object at that location in memory.
Here is a special use of "new" called "placement new":
Type *p = malloc( sizeof(Type) ); /* This only allocates memory */
::new(p) Type; /* This constructs an object at the address
specified by "p" */
For info on "placement new", try this:
http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10