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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:23:33+00:00 2026-05-10T20:23:33+00:00

Has anyone here ever used C++’s placement new? If so, what for? It looks

  • 0

Has anyone here ever used C++’s ‘placement new’? If so, what for? It looks to me like it would only be useful on memory-mapped hardware.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T20:23:34+00:00Added an answer on May 10, 2026 at 8:23 pm

    Placement new allows you to construct an object in memory that’s already allocated.

    You may want to do this for optimization when you need to construct multiple instances of an object, and it is faster not to re-allocate memory each time you need a new instance. Instead, it might be more efficient to perform a single allocation for a chunk of memory that can hold multiple objects, even though you don’t want to use all of it at once.

    DevX gives a good example:

    Standard C++ also supports placement new operator, which constructs an object on a pre-allocated buffer. This is useful when building a memory pool, a garbage collector or simply when performance and exception safety are paramount (there’s no danger of allocation failure since the memory has already been allocated, and constructing an object on a pre-allocated buffer takes less time):

    char *buf  = new char[sizeof(string)]; // pre-allocated buffer string *p = new (buf) string("hi");    // placement new string *q = new string("hi");          // ordinary heap allocation 

    You may also want to be sure there can be no allocation failure at a certain part of critical code (for instance, in code executed by a pacemaker). In that case you would want to allocate memory earlier, then use placement new within the critical section.

    Deallocation in placement new

    You should not deallocate every object that is using the memory buffer. Instead you should delete[] only the original buffer. You would have to then call the destructors of your classes manually. For a good suggestion on this, please see Stroustrup’s FAQ on: Is there a "placement delete"?

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

Sidebar

Related Questions

I'm wondering whether anyone here has ever used a skip list . It looks
Has anyone ever used the hidden class PackageParser in Android source code with java
Has anyone ever had an issue with iPhone settings icons not updating with new
Has anyone here created a Flash site or application that is ADA (Section 508)
Has anyone here tried to use a custom animation with MBProgressHUD. There is a
Aside from scalability issues, has anyone here actually stumbled upon a web-development problem where
Has anyone got any experience/thoughts on the CSLA.netContrib project on codeplex - here .
Can anyone help me understand what is going on here? Jenkins has been working
Has anyone used Hazelcast (preferably 2.1) with play framework 2.0/2.1 (not 1.2+)? I am
Has anyone ever run into this issue before? Sometimes the string displays, sometimes half

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.