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

Discussion in 'C++' started by PengYu.UT@gmail.com, Nov 4, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Mike Wahler Guest

    <> wrote in message
    news:...
    > 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
    Mike Wahler, Nov 4, 2006
    #2
    1. Advertising

  3. Guest

    On Nov 4, 1:23 pm, "Mike Wahler" <> wrote:
    > <> wrote in messagenews:...
    >
    > > 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, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sydex
    Replies:
    12
    Views:
    6,452
    Victor Bazarov
    Feb 17, 2005
  2. Geoffrey S. Knauth
    Replies:
    6
    Views:
    979
    Earl Purple
    Jan 18, 2006
  3. Arvid Requate
    Replies:
    2
    Views:
    971
    Alf P. Steinbach
    Jun 23, 2006
  4. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    236
    Sherm Pendley
    Oct 11, 2004
  5. Shriramana Sharma
    Replies:
    8
    Views:
    262
    Gerhard Fiedler
    Jun 18, 2013
Loading...

Share This Page