Sorry for asking this question, but actually I don't know about this. I have read in the following FAQ entry: Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?
Furthermore, there is no guarantee that the mechanism used by new and delete to acquire and release raw memory is compatible with
malloc()
andfree()
.
I just want to know that what is this "raw memory"?
In c you used malloc and free to allocate memory. If malloc rerurned a pointer casted to void, you would have more or less raw memory. The cpp pendant is new and delete. There is also the possibility with special casts to get untyped memory, so called raw memory pointed to by raw pointers. But it is fact that any ressource allocated by new or new[] must be freed by delete resp.delete[]. BUT NOT THE MEMORY ALLOCATED BY REPLACEMENT NEW.
"Raw memory" refers to blocks of memory, treated as unstructured arrays of bytes. Higher-level languages use these as the storage for objects; the program usually interacts with these objects, not the low-level byte values.
In C++, raw memory can be allocated dynamically using two different allocation functions:
operator new
, used to allocate from the free store when you create an object usingnew
malloc
from the C libraryMemory allocated by
new
must be released withdelete
; and memory allocated withmalloc
must be released withfree
.The line you quote explains that these might use different mechanisms to manage allocation; so that it's an error to use the wrong function to release memory (e.g. to allocate memory with
new
and try to release it withfree
).Raw memory refers to the unmanaged memory in C and C++. malloc, calloc, realloc, and free are low-level functions that simply deal with raw memory.
You can also refer this Stanford document about Raw memory