Create new C++ object at specific memory address?

后端 未结 5 1340
悲&欢浪女
悲&欢浪女 2020-11-30 00:32

Is it possible in C++ to create a new object at a specific memory location? I have a block of shared memory in which I would like to create an object. Is this possible?

5条回答
  •  无人及你
    2020-11-30 01:11

    if you want to allocate a lot of fine-grained objects, the best approach will be to use placement new in conjunction with some sort of a ring buffer. otherwise, you will have to keep track of the pointers aside from the object pointers themselves.

提交回复
热议问题