Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Austrian Coder

replace new with own new

This topic is 5638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I am writting actually a memory manager. Everything works great:
  
#include "memory_manager.h"
#include "iostream.h"

CMemoryManager MG(2*1024*1024);	// reserve 2 MB for the beginning


class z
{
public:
	int a1;
	int a2;
	int a3;
	int a4;
	int a5;
	int a6;
	int a7;
	int a8;
};

void main()
{
	cout << "Free memory: " << MG.GetFreeMemory() << " - Total memory: " << MG.GetTotalMemory() << endl;
	z* a;

	a = (z*)MG.Allocate(sizeof(z));

	cout << "Free memory: " << MG.GetFreeMemory() << " - Total memory: " << MG.GetTotalMemory() << endl;

	a->a5 = 5;

	cout << a->a5 << endl;

	....
	....
	....
}
  
Now I want to replace the standard new with a own functions, which uses MG.Allocate(). How can i do this? Thanks, Austrian Coder

Share this post


Link to post
Share on other sites
Advertisement
Thanks!

I have now maked my Memory manager to a singleton -> gMemoryMng.
And this is my new operator:

void* ::operator new(size_t size)
{
return gMemoryMng->Allocate(size);
}

And it works great

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!