new and delete implementation
Posted: Sun Sep 14, 2008 3:42 am
I've already implemented a malloc and free functions. Since I'm creating a C++ kernel, now I need to implement new and delete too...
Initially I thinked that
Is the only think I need. But I read that new and delete also call constructors and deconstructors. How can I call the contructor of the new class?
I also read that the return type of new isn't void * but a pointer to the type of the parameter.
Eg
How is this done in C++?
Thanks
Initially I thinked that
Code: Select all
void *operator new(size_t size) {
return malloc(size);
}
I also read that the return type of new isn't void * but a pointer to the type of the parameter.
Eg
Code: Select all
new(sizeof(short int)) returns short int *
new(Class1()) returns Class1 *
Thanks