473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

overload operator new with a spcialized memory manager instance

I am trying to find a way to overload operator new of a class to use a
specialzied memory manager. In my design multiple memory managers exist. I
need to pass the instance of a memory manager into operator new. In ANSI C,
it is quite simple, like this:

type_t* ansi_c_init(MemoryManager* m)
{
type_t* a = (type_t*)->alloc_bytes(sizeof(type_t));
a->memory_manager = m;
}
According to my read, the new() overload is actually a static method and can
not call any members. So my question is, it is a backward in C++? Is it even
possible to customize memory allocation with a specialized memory manager?
Aug 27 '08 #1
1 1514
On 2008-08-27 15:25:44 -0400, "Maximus" <ma*****@microsoft.comsaid:
I am trying to find a way to overload operator new of a class to use a
specialzied memory manager. In my design multiple memory managers exist. I
need to pass the instance of a memory manager into operator new. In ANSI C,
it is quite simple, like this:

type_t* ansi_c_init(MemoryManager* m)
{
type_t* a = (type_t*)->alloc_bytes(sizeof(type_t));
a->memory_manager = m;
}
According to my read, the new() overload is actually a static method and can
not call any members. So my question is, it is a backward in C++? Is it even
possible to customize memory allocation with a specialized memory manager?
void *operator new(size_t size, MemoryManager& m)
{
// whatever
}

FunkyMemoryManager mm;
new (mm) int(3); // calls operator new(size_t, MemoryManager&)
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Aug 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris E. Yoon | last post by:
I just want to hear people's opinions on this subject. My application has lots and lots of short-lived objects that use dynamic allocation/deallocation. After implementing its functionality, I...
7
by: Piotre Ugrumov | last post by:
I have tried to implement the overload of these 2 operators. ostream & operator<<(ostream &out, Person &p){ out<<p.getName()<<" "<<p.getSurname()<<", "<<p.getDateOfBirth()<<endl; return out; }...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
9
by: Tony | last post by:
I have an operator== overload that compares two items and returns a new class as the result of the comparison (instead of the normal bool) I then get an ambiguous operater compile error when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.