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 7664297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:16:18+00:00 2026-05-31T14:16:18+00:00

Can we place dynamically allocated objects at some other place than heap?? How will

  • 0

Can we place dynamically allocated objects at some other place than heap?? How will I define an overloaded new operator for that??

If I have some class Arena like

 class Arena{
      char area[2000];
 public:
      Arena(){}
 };

Arena my_arena(1000);

And I want to allocate objects from Arena my_arena..

Further, what are the possible drawbacks in such memory allocation as compared to allocation from the heap on the performance etc??

  • 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-31T14:16:20+00:00Added an answer on May 31, 2026 at 2:16 pm

    You can easily use placement new for this:

    MyClass* p = new (area) MyClass;
    

    There are two issues you have to be aware of, however:

    1. There is no guarantee that `area` will be correctly aligned for
      `MyClass`. I usually solve this by means of a union:

          union
          {
              double dummyForAlignment;
              //  Any other types which might be necessary...
              unsigned char area[2000];
          };
      

      This is very ad hoc; there’s no formal guarantee as to what types you
      have to add to be sure. In practice, instead of `double`, I use a union
      of most of the basic types, plus a couple of pointers, just to be sure.

    2. Because you’ve used new, the compiler won’t take care of
      destruction for you, as it would for a normal data member. You’ll have
      to call the destructor explicitly:

          p->~MyClass();
      

      Which means that you’ll have to keep track of how many objects of what
      types, and where, have been allocated.

    The drawbacks of this technique are the two points I’ve just mentionned.
    Plus, unless you keep a typed pointer to the constructed objects, you may
    have problems viewing them in a debugger.
    Still, it’s a useful technique for some specific uses: I use it in my
    Fallible class, in order to avoid the need of default constructor; the
    standard containers require it, and of course, pre-standard vector or
    array classes generally used it as well. It’s also useful for various
    variant classes; I presume it is used in boost::variant, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where in this pattern I can place services, about which I some much hear
There are <meta> tags and other things you can place in the <head> of
I've ran into one small problem. I am dynamically generating some controls and place
How can I load images dynamically in place of cell data in a report
In the iPad application Pages, the user can manually enter text and place images/other
I need to dynamically create some views in my app and place some buttons
I have an website where people can place a vote like this: http://mysite.com/vote/25 This
Is it possible to have multiple folders where I can place applications to be
i am using vb.net i just wanna ask if we can place a picture
Can one place an arbitrary program (firefox, openoffice, etc...) in a QX11EmbedContainer? The fllowing

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.