Connecting Tech Pros Worldwide Forums | Help | Site Map

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

PengYu.UT@gmail.com
Guest
 
Posts: n/a
#1: Nov 4 '06
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


Mike Wahler
Guest
 
Posts: n/a
#2: Nov 4 '06

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



<PengYu.UT@gmail.comwrote in message
news:1162653090.149661.139220@i42g2000cwa.googlegr oups.com...
Quote:
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;
Quote:
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



PengYu.UT@gmail.com
Guest
 
Posts: n/a
#3: Nov 4 '06

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




On Nov 4, 1:23 pm, "Mike Wahler" <mkwah...@mkwahler.netwrote:
Quote:
<PengYu...@gmail.comwrote in messagenews:1162653090.149661.139220@i42g2000cwa.g ooglegroups.com...
>
Quote:
Hi,
>
Quote:
In FFTW (http://www.fftw.org/), it defines the funciton fftw_malloc to
allocate memory properly aligned.
>
Quote:
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.
Quote:
>
Quote:
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.

Closed Thread