Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 937859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:32:44+00:00 2026-05-15T21:32:44+00:00

I have a very large, spread out class that is essentially a very contrived

  • 0

I have a very large, spread out class that is essentially a very contrived two dimensional linked list. I want to be able to “compile” it, by which I mean I want to finalize the list, so that only read accesses may be made, and then move all the elements into contiguous memory spaces. My rough solution is this:

#include <new>
...
MyListNode* pool = new MyListNode[length];
new(&pool[position]) MyListNode();

The trouble is that I essentially have two classes, one allocated with new and the other allocated with this method up here, and when I try to delete any of the objects allocated by the above method, glibc kills the program because of an invalid pointer.

The natural solution is to create two classes, and just use runtime polymorphism to provide one interface but two implementation, etc. Is there any way that the memory standard in C++ permits this kind of jiggery pokery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:32:45+00:00Added an answer on May 15, 2026 at 9:32 pm

    Are you calling delete on one of the objects in your array? Or are you manually invoking the destructor to mirror the placement new?

    Since you have one call to non-placement new, you should only have one call to delete. And since you have n-calls to placement-new, you should manually invoke the destructor n times.

    So, you may want something like this:

    // Allocate an array of chars instead of an array of MyListNode.  Since we
    // are going to use placement new, this is necessary if MyListNode has a
    // a default constructor
    MyListNode* pool = static_cast<MyListNode *>(new char[sizeof(MyListNode) * length);
    for (size_t position = 0; position < length; ++position)
        new(&pool[position]) MyListNode();
    
    ...
    
    for (position = 0; position < length; ++position)
        pool[position].~MyListNode()
    
    delete[] static_cast<char *>(pool);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very large list Suppose I do that (yeah, I know the
I want to build an enterprise application that will have very large number of
I have a structure (class) that keeps very large number of numbers (either float,
I have very large Iterators that I want to split into pieces. I have
I have a very large possible data set that I am trying to visualize
I have a very large set of permissions in my application that I represent
I have very large string lists and arrays and i found 2 issues that
Have a very large program where there is always a superview that just encompasses
I have large list of the drop-down menu. Some of the option have very
Suppose, I have very large foreach loop. I want put this loop into try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.