c++ - Are these placement new macros correct? -


I made some macros to make the placement a little easier. I was just wondering if there is a clear case where it Will not work. Thank you. (

I'm not an expert in the placement, but there you can use the macro There are some issues about how to define

problem1

The most obvious problem is the use of cast (TYPE *) STORAGE for storage space This is incorrect The appointment is just another C ++ function and it participates in tasks such as overload resolution. Due to voluntary covering of a particular type of storage, the appointment can bind to a different operator which the user expects.

For example, the following two definitions of appointment are valid: your macro will likely call the wrong call.

Zero * _cdecl operator new (size_t cbSize, Zero * PV); Zero * _cdecl operator new (size_t cbSize, SomeType * pv) -

...

  // These two calls separate overload Zero * p = malloc (Sizeof (SomeType)); SomeType * f1 = CONSTRUCT_INPLACE (some type, p, ()) some type * f2 = new (p) some type ();  

I wrote a blog post a few times before that how you can use this type of overload resolution to implement custom olocator.

Points 2

To prevent malicious detailing the bug, the expression STORAGE should be wrapped in the macro.

: New ((TYPE *) (STORAGE) Type INIT

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -