Topic: What address should placement new return?


Author: Peter Johansson <Peter.Johansson@uab.ericsson.se>
Date: 2000/02/24
Raw View
--------------AD3D9CB082587E375B7909C3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I have an application that performs placement new on various classes
where the behavior differ between platforms.

What I do (essentially) is this:

    I have a class:
    class MyClass
    {
    private:
        char* thisIsTheOnlyDataInTheClass;
    };

    Somewhere in the code I have allocated an array of characters e.g.:
    char areaAllocatedForPnew[4000];

    and then I perform a placement new on it:
    MyClass* instance = new (areaAllocatedForPnew) MyClass[100];

    This is where the fuzzy things happen.
    lets say for argument sake that the address to areaAllocatedForPnew
is 0xF0C000.
    Then, on an Intel Windows platform, the address to 'instance' after
the placement new is 0xF0C000 (as I expected).
    However, on an Alpha TRU64 platform, the address to 'instance' is
always 0xF0C008 (the original + 8).

    Question:
    What address should placement new return? Is it at any time allowed
to not return the same address as supplied to it?

/ Peter


--------------AD3D9CB082587E375B7909C3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I have an application that performs placement new on various classes where
the behavior differ between platforms.
<p>What I do (essentially) is this:
<p>&nbsp;&nbsp;&nbsp; I have a class:
<br>&nbsp;&nbsp;&nbsp; class MyClass
<br>&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp; private:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char* thisIsTheOnlyDataInTheClass;
<br>&nbsp;&nbsp;&nbsp; };
<p>&nbsp;&nbsp;&nbsp; Somewhere in the code I have allocated an array of
characters e.g.:
<br>&nbsp;&nbsp;&nbsp; char areaAllocatedForPnew[4000];
<p>&nbsp;&nbsp;&nbsp; and then I perform a placement new on it:
<br>&nbsp;&nbsp;&nbsp; MyClass* instance = new (areaAllocatedForPnew) MyClass[100];
<p>&nbsp;&nbsp;&nbsp; This is where the fuzzy things happen.
<br>&nbsp;&nbsp;&nbsp; lets say for argument sake that the address to areaAllocatedForPnew
is 0xF0C000.
<br>&nbsp;&nbsp;&nbsp; Then, on an Intel Windows platform, the address
to 'instance' after the placement new is 0xF0C000 (as I expected).
<br>&nbsp;&nbsp;&nbsp; However, on an Alpha TRU64 platform, the address
to 'instance' is always 0xF0C008 (the original + 8).
<p><b>&nbsp;&nbsp;&nbsp; Question:</b>
<br>&nbsp;&nbsp;&nbsp; What address should placement new return? Is it
at any time allowed to <u>not</u> return the same address as supplied to
it?
<p>/ Peter
<br>&nbsp;</html>

--------------AD3D9CB082587E375B7909C3--

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 2000/02/24
Raw View
AFAIK you can never use placement array new because
there is way to know how much padding the compiler
will insert before the array.

--

Valentin Bonnard

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]