By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,388 Members | 1,823 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,388 IT Pros & Developers. It's quick & easy.

How to overload the new operator for std::complex<double>?

P: n/a
Hi,

In FFTW (http://www.fftw.org/), it defines the funciton fftw_malloc to
allocate memory properly aligned.

However, I only want to use new to allocate memory for
std::complex<double>. Can some body show me how to redefine the new
operator for an class already defined in the library?

Thanks,
Peng

Nov 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

<Pe*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Hi,

In FFTW (http://www.fftw.org/), it defines the funciton fftw_malloc to
allocate memory properly aligned.

However, I only want to use new to allocate memory for
std::complex<double>.
std::complex<double*p = new std::complex<double>;
/* do stuff with the object */
delete p;
Can some body show me how to redefine the new
operator for an class already defined in the library?
You don't need to redefine 'new'.

BTW why do you feel you need to dynamically allocate
your object(s) anyway?

-Mike

Nov 4 '06 #2

P: n/a


On Nov 4, 1:23 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
<PengYu...@gmail.comwrote in messagenews:11**********************@i42g2000cwa.g ooglegroups.com...
Hi,
In FFTW (http://www.fftw.org/), it defines the funciton fftw_malloc to
allocate memory properly aligned.
However, I only want to use new to allocate memory for
std::complex<double>.std::complex<double*p = new std::complex<double>;
/* do stuff with the object */
delete p;
I was asking how to redefine the "new" operator, such that when I call
new std::complex<double>[10]
it will call fftw_malloc function to allocate the memory.
>
Can some body show me how to redefine the new
operator for an class already defined in the library?You don't need to redefine 'new'.

BTW why do you feel you need to dynamically allocate
your object(s) anyway?
For example, the array is defined in an class, and its size is not
fixed.

Nov 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.