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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:11:57+00:00 2026-05-27T19:11:57+00:00

I am writing a memory manager in c++. The aim is to allocate a

  • 0

I am writing a memory manager in c++. The aim is to allocate a set amount of memory at the start using malloc and then overload new and delete so that it uses that memory. I almost have it working my only problem is how i am keeping track of what is where in the memory.

I created a vector of structs which holds information such as size, location and if it is free or not.

The problem is when i call push_back it attempts to use my overloaded new function. This is where it fails because it can’t use my overloaded new until it has pushed back the first structure of information.

Does anyone know how i can resolve this or a better way to keep track of the memory?

  • 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-27T19:11:58+00:00Added an answer on May 27, 2026 at 7:11 pm

    Don’t overload global operator new!

    The easiest and (WARNING; subjective ->) best solution would be to define your own Allocator which you’ll use when dealing with allocation on the free-store (aka. heap). All STL containers have support for passing an AllocatorType as a template argument.

    Overloading global operator new/operator delete might seem like a neat solution, but I can almost guarantee you that it will cause you troubles as the developing goes by.

    Inside this custom made allocator you can keep track of what goes where, but make the internal std::vector (or whatever you’d like to use, a std::map seems more fitting to me) will use the default operator new/operator delete.


    How do I create my own allocator?

    The link below will lead you to a nice document with information regarding this matter:

    • stdcxx.apache.org – Building Your Own Allocators (heavily recommended)

    Using a custom allocator when required/wanted will make you not run into any chicken and egg problem when trying to allocate memory for the allocator that will allocate memory, but the allocator must have allocated memory to use the allocator methods.. and what will allocate memory for the allocator but the allocator? Well we will need to allocate memory for that allocator and that allocator must have it’s own allocator, though that allocator need memory, provided by another allocator?

    Maybe I should just get myself a dog instead, they don’t lay eggs – right?

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

Sidebar

Related Questions

I've written a c/c++ memory manager for heap allocations (overloaded new/delete and malloc/realloc/free, based
When writing C++ code I've learned that using the stack to store memory is
Hi I'm writing some test stuff to see the amount of memory that allocated
I'm writing memory manager for Windows in c++. I've created a class that allocates
I am writing a simple memory manager for my application which will free any
I'm writing a simple linked list based memory manager in the form: ...Header|Block|Header|Block... with
The java memory model mandates that writing a int is atomic: That is, if
Memory Issues So I am writing an app that should be able to page
When writing a custom string class that stores UTF-8 internally (to save memory) rather
I'm writing the memory manager for an application, as part of a team of

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.