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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:48:54+00:00 2026-05-21T05:48:54+00:00

According to C++ Primer 4th edition, page 755, there is a note saying: Modern

  • 0

According to C++ Primer 4th edition, page 755, there is a note saying:

Modern C++ programs ordinarily ought to use the allocator class
to allocate memory. It is safer and more flexible.

I don’t quite understand this statement.
So far all the materials I read teach using new to allocate memory in C++.
An example of how vector class utilize allocator is shown in the book.
However, I cannot think of other scenarios.

Can anyone help to clarify this statement? and give me more examples?
When should I use allocator and when to use new? Thanks!

  • 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-21T05:48:54+00:00Added an answer on May 21, 2026 at 5:48 am

    For general programming, yes you should use new and delete.

    However, if you are writing a library, you should not!
    I don’t have your textbook, but I imagine it is discussing allocators in the context of writing library code.

    Users of a library may want control over exactly what gets allocated from where. If all of the library’s allocations went through new and delete, the user would have no way to have that fine-grained level of control.

    All STL containers take an optional allocator template argument. The container will then use that allocator for its internal memory needs. By default, if you omit the allocator, it will use std::allocator which uses new and delete (specifically, ::operator new(size_t) and ::operator delete(void*)).

    This way, the user of that container can control where memory gets allocated from if they desire.

    Example of implementing a custom allocator for use with STL, and explanation: Improving Performance with Custom Pool Allocators for STL

    Side Note: The STL approach to allocators is non-optimal in several ways. I recommend reading Towards a Better Allocator Model for a discussion of some of those issues.

    Edit in 2019: The situation in C++ has improved since this answer was written. Stateful allocators are supported in C++11, and that support was improved in C++17. Some of the people involved in the “Towards a Better Allocator Model” were involved in those changes (eg: N2387), so that’s nice (:

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

Sidebar

Related Questions

From C++ Primer, 5th Edition, page 407: All static duration variables share the following
According to Microsoft ( link ), there are two ways to start a task:
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to
According to this page here if you have proper application binary and .dSYM file
according to this description I just created an nine-patch image. I named it androidRow.9.png
According to this question Raphael - event when mouse near element i create a
According to the documentation: public static <T> int binarySearch(T[] a, T key, Comparator<? super
According to C++03 Standard (23.1/3) only copy-constructible class objects can be stored in STL
According to a book I have (Eclipse for Minor Geniuses or something like that),
according to the CUDA programming guide, the value returned by the texture fetch is

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.