| One useful case for placement new is when it's used in conjunction with shared memory, which is
shared by a group of processes. I am in great need of this feature. Is there a plan to support it?
If yes, what's the time frame?
Thanks,
-James (DTN: 881-2531, email: [email protected])
|
| > One useful case for placement new is when it's used in
> conjunction with shared memory, which is shared by a group of
> processes. I am in great need of this feature. Is there a plan
> to support it? If yes, what's the time frame?
If you mean placement new, it is there in <new.hxx> now:
inline void* operator new(size_t, void* p) { return p; }
If you mean shared memory, you need to use operating system
specific methods to set that up.
You can use placement new to construct a C++ object into
shared memory, but for a lot of objects that doesn't help
much. See for example topic 1254 here. Any pointers within
the object (and behind the scenes the implementation may use
pointers for virtual function vtbls, virtual base class
objects, etc.) will usually be valid for only one of the
processes accessing the shared memory.
"Plain old data" objects (POD objects) like C structs, where
none of the fields are pointers, can be shared this way.
Dan
|
| RE. 4: Thanks for the answer and the pointer. I'll give an example to clarify my question.
class Foo {
...;
};
...
void* base;
base = mmap(...); // PROT_READ | PROT_WRITE and MAP_SHARED are set
pFoo = new (base) Foo();
...
When compiled the code with DEC C++ V5.5-004 on Digital Unix 4.0, I received an error
stating:
"cxx: Error: ...: In this statement, "new (base) Foo" supplies 2 arguments, but 1 is expected.
What did I do wrong here?
-James
|