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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:45+00:00 2026-05-25T22:26:45+00:00

Update: The following problem appears to depend on the -fwhole-program option. I’ve been playing

  • 0

Update: The following problem appears to depend on the -fwhole-program option.

I’ve been playing around a bit with memory allocation, and I encountered a small mystery: In GCC (4.6), how does std::string allocate its memory [edit]when I compile with -fwhole-program[/]?

Have this following test program:

#include <new>
#include <string>
#include <iostream>
#include <cstdlib>

void * operator new(std::size_t n) throw(std::bad_alloc)
{
  void * const p = std::malloc(n);

  if (p == NULL) throw std::bad_alloc();

  std::cerr << "new() requests " << n << " bytes, allocated at " << p << ".\n";

  return p;
}

void operator delete(void * p) noexcept
{
  std::cerr << "delete() at " << p << ".\n";
  std::free(p);
}

int main()
{
  std::string s = "Hello world.";
}

When I use any other dynamic container (which uses std::allocator<T>), the allocator uses ::operator new, and so I see the debug messages happily. However, with std::string, I see nothing at all. I’m sure that dynamic allocation happens, though, as I can confirm with valgrind (13 plus string length bytes are allocated). I went through several source files and the standard, and I’m pretty sure that the template is std::basic_string<T, std::char_traits<T>, std::allocator<T>>, so I’m at a loss why I don’t see the messages from my replaced allocation functions.

Can anyone shed any light on this conundrum? What do I do to track string allocations? Also, could anyone run this through some other compiler and see if it produces any output?

(For example: if I add std::map<int, int> m { { 0, 1 } };, I have output new() requests 24 bytes, allocated at 0x8d53028 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-25T22:26:46+00:00Added an answer on May 25, 2026 at 10:26 pm

    Looking at the output of g++ ... -S with / without -fwhole-program it appears that the whole custom new/delete operators aren’t emitted at all when using fwhole-program.

    I’m starting to suspect we’re looking at a bug here.

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

Sidebar

Related Questions

I face the following problem function book($memberid, $classid){ if (!book){ // update the db
I'm trying to resolve the following problem: [.Net 2.0, CLR 2.5.something, 64 bit machine,
Update: I left the following javascript code in to show how the problem developed
I'll like to update the following rewrite condition to only allow one particular subdomain.
Does Ado.net check if the following update is required? ADDRESS table with a TOWN
I have the following query: UPDATE lessonstatus INNER JOIN user ON lessonstatus.user_id = user.user_id
I have the following code: UPDATE myTable SET Col1 = @Value However, I have
I have an SQL query that takes the following form: UPDATE foo SET flag=true
What is the order of evaluation in the following query: UPDATE tbl SET q
Currently I have to write the following to update an element already contained in

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.