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

  • Home
  • SEARCH
  • 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 4016606
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:45:37+00:00 2026-05-20T09:45:37+00:00

I am currently working on an application for a low-memory platform that requires an

  • 0

I am currently working on an application for a low-memory platform that requires an std::set of many short strings (>100,000 strings of 4-16 characters each). I recently transitioned this set from std::string to const char * to save memory and I was wondering whether I was really avoiding all that much overhead per string.

I tried using the following:

std::string sizeTest = "testString";
std::cout << sizeof(sizeTest) << " bytes";

But it just gave me an output of 4 bytes, indicating that the string contains a pointer. I’m well aware that strings store their data in a char * internally, but I thought the string class would have additional overhead.

Does the GCC implementation of std::string incur more overhead than sizeof(std::string) would indicate? More importantly, is it significant over this size of data set?

Here are the sizes of relevant types on my platform (it is 32-bit and has 8 bits per byte):

char: 1 bytes
void *: 4 bytes
char *: 4 bytes
std::string: 4 bytes

  • 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-20T09:45:37+00:00Added an answer on May 20, 2026 at 9:45 am

    Well, at least with GCC 4.4.5, which is what I have handy on this
    machine, std::string is a typdef for std::basic_string<char>, and
    basic_string is defined in
    /usr/include/c++/4.4.5/bits/basic_string.h. There’s a lot of
    indirection in that file, but what it comes down to is that nonempty
    std::strings store a pointer to one of these:

      struct _Rep_base
      {
    size_type       _M_length;
    size_type       _M_capacity;
    _Atomic_word        _M_refcount;
      };
    

    Followed in-memory by the actual string data. So std::string is
    going to have at least three words of overhead for each string, plus
    any overhead for having a higher capacity than `length (probably
    not, depending on how you construct your strings — you can check by
    asking the capacity() method).

    There’s also going to be overhead from your memory allocator for doing
    lots of small allocations; I don’t know what GCC uses for C++, but
    assuming it’s similar to the dlmalloc allocator it uses for C, that
    could be at least two words per allocation, plus some space to align
    the size to a multiple of at least 8 bytes.

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

Sidebar

Related Questions

We are currently working on an application that will use a WCF service. The
In an application that I am currently working on, a requirement is to bring
A database application that I'm currently working on, stores all sorts of settings in
I am currently working on an web application that uses ASP.NET 2.0 framework. I
I'm currently working on an application that needs to use Windows and Forms authentication
I am currently working on rails3 application that uses jQuery. I have a javascript
A web application I am currently working on appears to be leaking memory: with
I'm currently working on a Flash application that needs to save files to Drupal.
I'm currently working on a windows application which is entirely model, that is, it
I'm currently working on an application with a frontend written in Adobe Flex 3.

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.