Tuesday, November 9, 2010

Using Allocators versus Placement New

Given that ptr is a pointer to an object, then:

ptrToObject = new (ptr) Object; uses placement new.

and

ptrToObject = new (*ptr) Object; specifies and allocator.

If you want to place an object at a specific address, use placement new.

If you want new to use a specific allocator, pass the allocator object to new. Allocators can place your object anywhere they want. Examples of allocators include those that manage various heaps and those that managed reusable blocks of memory.

No comments:

Post a Comment