K
karthikbalaguru
Hi,
I find that articles stating that 'placement new' constructs an object
on a pre-allocated buffer and so takes less time.
Actually, we have to consider the allocation of the buffer and then
the construction of object using 'placement new'. So, Effectively it
should be taking more time . What do you think ?
I think,
'placement new' time = Time for creation of pre-allocated buffer +
Time for doing the allocation in
pre-allocated buffer using
'placement new'.
Ex :
void placementnew{
char *buf = new char[1000]; // pre-allocated buffer
string *p = new(buf)string("hi"); // placement new in turn depends
on buf
}
So, i think, it should be as below :
'placement new' time(p) = Time for creation of pre-allocated buffer
called 'buf' + Time for doing the
allocation in
pre-allocated buffer
using 'placement
new' for 'hi'.
So, How could 'placement new' be stated to be faster ?
Further, what is the advantage in using 'placement new'. It in turn is
depending on the pre-allocated buffer in heap that is assigned using
'new'. So, how does 'placement new' prove to be good in comparison
with 'new' as it indirectly depends on heap ?
Why was 'placement new' introduced in c++ ? What are the practical
areas of application of 'placement new' ?
Thx in advans,
Karthik Balaguru.
I find that articles stating that 'placement new' constructs an object
on a pre-allocated buffer and so takes less time.
Actually, we have to consider the allocation of the buffer and then
the construction of object using 'placement new'. So, Effectively it
should be taking more time . What do you think ?
I think,
'placement new' time = Time for creation of pre-allocated buffer +
Time for doing the allocation in
pre-allocated buffer using
'placement new'.
Ex :
void placementnew{
char *buf = new char[1000]; // pre-allocated buffer
string *p = new(buf)string("hi"); // placement new in turn depends
on buf
}
So, i think, it should be as below :
'placement new' time(p) = Time for creation of pre-allocated buffer
called 'buf' + Time for doing the
allocation in
pre-allocated buffer
using 'placement
new' for 'hi'.
So, How could 'placement new' be stated to be faster ?
Further, what is the advantage in using 'placement new'. It in turn is
depending on the pre-allocated buffer in heap that is assigned using
'new'. So, how does 'placement new' prove to be good in comparison
with 'new' as it indirectly depends on heap ?
Why was 'placement new' introduced in c++ ? What are the practical
areas of application of 'placement new' ?
Thx in advans,
Karthik Balaguru.