Is it possible to recreate an array which has been “destroyed” by placement new?

geza 07/11/2018 at 17:56. 0 answers, 120 views

I was thinking about how to solve this problem with placement new, and I faced a problem.

Suppose, that I allocate a float array:

float *f = new float[10];

Then, I use this storage to store doubles (note that I assume that f is properly aligned, and sizeof(float)*2==sizeof(double)), which destroys the float array:

double *d = new(f) double;
for (int i=1; i<5; i++) {
    new(d+i) double;

Now, is there a way to recreate the float array? The most intuitive solution

f = new(f) float[10];

may not work, as new[] can have a space overhead, so float[10] may not fit into f.

No Answers Yet

Related questions

Hot questions


Popular Tags