How do you write your own "operator new"

How do you write your own "operator new"

Post by Geof » Sat, 09 Sep 2000 10:19:21



I would like to write my own "new".

I am just trying to intercept all calls to "new" so that memory allocation
comes from a block of memory I have set aside.
How does the contsuctor get called after the memory allocation?

Thanks,

Geoff

 
 
 

How do you write your own "operator new"

Post by Scott Neugrosch » Sat, 09 Sep 2000 13:26:21


go to comp.lang.c++

> I would like to write my own "new".

> I am just trying to intercept all calls to "new" so that memory allocation
> comes from a block of memory I have set aside.
> How does the contsuctor get called after the memory allocation?

> Thanks,

> Geoff


 
 
 

How do you write your own "operator new"

Post by son.. » Sat, 09 Sep 2000 13:48:40




Quote:> I would like to write my own "new".

> I am just trying to intercept all calls to "new" so that memory
allocation
> comes from a block of memory I have set aside.

Unless you meant something else...
#include<new.h>

void * operator new ( size_t t ) {

     // grab t bytes
     return t bytes ;
    }

The ctor will be invoked in this returned chunk of memory by the
compiler. So don t make the mistake of invoking the ctor inside the
definition.

PS : comp.lang.C++.moderated is a better place for C++ related postings.

Quote:> How does the contsuctor get called after the memory allocation?

> Thanks,

> Geoff

Sent via Deja.com http://www.deja.com/
Before you buy.