Whether there are situations when the object needs to be created in memory to a certain address? Where it can be necessary (example)?
Thank you.
Whether there are situations when the object needs to be created in memory to a certain address? Where it can be necessary (example)?
Thank you.
You seem to be asking if in a C++ application it's ever necessary to construct an object at a specific address.
Normally, no. But there are exceptions, and the C++ language does support it.
One such exception is when building a kind of cache system for small objects in order to avoid frequent small allocations. One would first construct a large buffer, and then when the client code wants to construct a new small object, the caching system would construct it within this large buffer.
Take a look at placement new: " What uses are there for "placement new"? "
Good examples are writing your own memory allocator, garbage collector, or trying to precisely lay out memory due to cache performance.
It's a niche thing, but sometimes very useful.
In C++, one may need to construct an object at a specific given address when implementing a pool allocator. For example, Boost Pool: http://www.boost.org/doc/libs/1_47_0/libs/pool/doc/index.html