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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:35:23+00:00 2026-05-22T20:35:23+00:00

I’m making an application that is going to be using many dynamically created objects

  • 0

I’m making an application that is going to be using many dynamically created objects (raytracing). Instead of just using [new] over and over again, I thought I’d just make a simple memory system to speed things up. Its very simple at this point, as I don’t need much.

My question is: when I run this test application, using my memory manager uses the correct amount of memory. But when I run the same loop using [new], it uses 2.5 to 3 times more memory. Is there just something I’m not seeing here, or does [new] incur a huge overhead?

I am using VS 2010 on Win7. Also I’m just using the Task Manager to view the process memory usage.

template<typename CLASS_TYPE>
class MemFact
{
public:
  int m_obj_size; //size of the incoming object
  int m_num_objs; //number of instances
  char* m_mem; //memory block

  MemFact(int num) : m_num_objs(num)
  {
    CLASS_TYPE t;
    m_obj_size = sizeof(t);
    m_mem = new char[m_obj_size * m_num_objs);
  }

  CLASS_TYPE* getInstance(int ID)
  {
    if( ID >= m_num_objs) return 0;
    return (CLASS_TYPE*)(m_mem + (ID * m_obj_size));
  }

  void release() { delete m_mem; m_mem = 0; }
};
/*---------------------------------------------------*/
class test_class
{
  float a,b,c,d,e,f,g,h,i,j; //10 floats
};
/*---------------------------------------------------*/
int main()
{
  int num = 10 000 000; //10 M items
  // at this point we are using 400K memory
  MemFact<test_class> mem_fact(num);
  // now we're using 382MB memory
  for(int i = 0; i < num; i++)
     test_class* new_test = mem_fact.getInstance(i);
  mem_fact.release();
  // back down to 400K
  for(int i = 0; i < num; i++)
     test_class* new_test = new test_class();
  // now we are up to 972MB 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-22T20:35:24+00:00Added an answer on May 22, 2026 at 8:35 pm

    There is a minimum size for a memory allocation, depending on the CRT you are using. Often that’s 16 bytes. Your object is 12 bytes wide (assuming x86), so you’re probably wasting at least 4 bytes per allocation right there. The memory manager also has it’s own structures to keep track of what memory is free and what memory is not — that’s not free. Your memory manager is probably much simplier (e.g. frees all those objects in one go) which is inherently going to be more efficient than what new does for the general case.

    Also keep in mind that if you’re building in debug mode, the debugging allocator will pad both sides of the returned allocation with canaries in an attempt to detect undefined behavior. That’ll probably put you over the 16 byte boundary and into the next one — probably a 32 byte allocation, at least. That’ll be disabled when you build in release mode.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.