RE:malloc.h -> mmalloc.h

Masaharu Goto (MXJ02154@nifty.ne.jp)
Mon, 19 Jul 1999 06:16:01 +0900


Hello,

>hello ppl
>im having problems with memory allocation
>i would like to know what are the default functions and parameters
>for the standard <malloc.h> C library functions in root :)
>
>thanks

I am not quite sure the true meaning of your question. I try to answer
as much as I can.

Cint and ROOT/CINT support following ANSI C standard function.

void *malloc(size_t size);
void free(void* ptr);

and C++ new/delete operators.

void* operator new(size_t size);
void* operator new(size_t size,void* arena);
void operator delete(void* ptr);

For memory allocation, you can use either of following.

1) double *pdbl = (double*)malloc(sizeof(double));
free((void*)pdbl);

2) double *pdbl = new double;
delete pdbl;

3) char buf[100];
double *pdbl = new((void*)buf) double;
// do not delete pbl in this case

This is almost full C/C++ spec. Limitation is that you can not overload
operator new/delete in interpreted code.

Thank you
Masaharu Goto