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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:45:08+00:00 2026-05-11T16:45:08+00:00

My application is mostly organised in layers so I found that something like the

  • 0

My application is mostly organised in layers so I found that something like the APR memory pools would be the best way.

While reading on SO about C++ placement new posts here & here, and a more generic C allocation question I was thinking about hand-crafting a hierarchical pool allocator as suggested in one post, but in the pure NYI tradition I’m first asking if something like this already exists.

It could also have the nice property of being able to give back unused memory to the OS (since allocation could be done with mmap(MAP_ANON)) or could be allocating from the stack as suggested Ferrucico here.

  • 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-11T16:45:08+00:00Added an answer on May 11, 2026 at 4:45 pm

    I know of another good hierarchical memory allocator, but it calls malloc underneath the covers.

    talloc is a hierarchical pool based memory allocator with destructors. It is the core memory allocator used in Samba4, and has made a huge difference in many aspects of Samba4 development.

    To get started with talloc, I would recommend you read the talloc guide.

    That being said, Glibc’s malloc already uses mmap(MAP_ANON) for allocation larger than mmap_threshold, which you can set via mallopt(M_MMAP_THRESHOLD, bytes). By default it is dynamically adjusted between

    /*
      MMAP_THRESHOLD_MAX and _MIN are the bounds on the dynamically
      adjusted MMAP_THRESHOLD.
    */
    
    #ifndef DEFAULT_MMAP_THRESHOLD_MIN
    #define DEFAULT_MMAP_THRESHOLD_MIN (128 * 1024)
    #endif
    
    #ifndef DEFAULT_MMAP_THRESHOLD_MAX
      /* For 32-bit platforms we cannot increase the maximum mmap
         threshold much because it is also the minimum value for the
         maximum heap size and its alignment.  Going above 512k (i.e., 1M
         for new heaps) wastes too much address space.  */
    # if __WORDSIZE == 32
    #  define DEFAULT_MMAP_THRESHOLD_MAX (512 * 1024)
    # else
    #  define DEFAULT_MMAP_THRESHOLD_MAX (4 * 1024 * 1024 * sizeof(long))
    # endif
    #endif
    

    Watch out if you lower it; by default no more than #define DEFAULT_MMAP_MAX 65536 pieces will be allocated using mmap. This can be changed with mallopt(M_MMAP_MAX, count), but using many mmaps has an overhead.

    The environment variables MALLOC_MMAP_THRESHOLD_ etc. will also set these options.

    Obviously, memory that malloc allocates with mmap is freed with munmap. I’m not sure if any of this is documented anywhere outside of Glibc’s source code, or has any compatibility guarantees.

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

Sidebar

Ask A Question

Stats

  • Questions 158k
  • Answers 158k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer iTextSharp. I'm working with it now and I've found the… May 12, 2026 at 11:19 am
  • Editorial Team
    Editorial Team added an answer As far as I can tell Guid.NewGuid() should be sufficient. May 12, 2026 at 11:19 am
  • Editorial Team
    Editorial Team added an answer This is logged as an issue on github, it would… May 12, 2026 at 11:19 am

Related Questions

I need to detect whether my application is running within a virtualized OS instance
I am planning on porting a PHP application over to Python. The application is
I have a website running a basic ASP.NET application that is mostly used from
Our application takes significantly more time to launch after a reboot (cold start) than

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.