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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:09:10+00:00 2026-06-08T07:09:10+00:00

I’m writing a stack based allocator for STL. The idea is to allocate a

  • 0

I’m writing a stack based allocator for STL. The idea is to allocate a big chunk of memory once and let it build up while objects are constructed and then reset it to zero when needed. For example, this could be used for storing level information for a game or for objects that are created for a single iteration of a game loop. When you load a level you build up the stack, when you need to load a new a level you just reset the top pointer to the beginning, no OS calls needed.

Now my issue is the way the standard allocator does things, namely the deallocate() function. In this article i can read that

In the default allocator, the block of storage is deallocated using
::operator delete.

which implies that by using the deallocate() function both the memory is freed and the destructor is called. Now for the purpouse of my allocator i can make the deallocate() function to be empty, since i’m not going to deallocate memory for individual objects.

So, the question is, how do the STL containers use the allocator class to create new objects? Since the default allocator uses new and delete, do the containers ever call construct() or destroy()? Should i make my deallocate() function also call the descrutor?

I guess the same question goes for the allocate() and construct() methods.

  • 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-06-08T07:09:12+00:00Added an answer on June 8, 2026 at 7:09 am

    which implies that by using the deallocate() function both the memory
    is freed and the destructor is called

    No it doesn’t. ::operator delete is the global delete function, it just frees the memory. The delete operator is a different thing, despite the similarity of name — it destructs and then calls a delete function (either the global delete function or an overload).

    The destructor is called by the destroy function of the allocator.

    Standard containers use allocate to get some memory, then construct if and when they need that memory to contain an element, destroy if and only if they constructed, and deallocate to free the memory. For example:

    {
        std::vector<int> v; // may or may not call anything on the allocator
        v.reserve(10000); // calls 'allocate'
        v.resize(100); // calls 'construct' 100 times
        v.resize(50); // calls 'destroy' 50 times
    } // destructor calls 'destroy' 50 times and then 'deallocate'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am writing an app with both english and french support. The app requests
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.