[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

2079.0. "What is the new/delete equivalent of realloc() ?" by OOTOOL::HIGGS (SQL is a camel in disguise) Mon Jul 25 1994 21:25

T.RTitleUserPersonal
Name
DateLines
2079.1There is no equivalent for realloc()CAIMAN::JOHNSTONTue Jul 26 1994 05:5861
2079.2I was afraid of that...OOTOOL::HIGGSSQL is a camel in disguiseTue Jul 26 1994 13:415
2079.3placement new is useful when used with shared memoryTUXEDO::LUThu Apr 10 1997 17:387
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: jlu@dcom.zko.dec.com)
2079.4SPECXN::DERAMODan D'EramoThu Apr 10 1997 18:0024
>    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
2079.5question by exampleTUXEDO::LUThu Apr 10 1997 19:0521
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
2079.6DECC::J_WARDThu Apr 10 1997 19:245
you forgot to #include <new.h>

Only the default new can be used without inclusion of
new.h.
2079.7TUXEDO::LUThu Apr 10 1997 19:413
RE. 5	Oops..., thanks for the prompt answer.

-James