[malloc vs new]
If you are a C programmer, you may be wondering what was wrong with the malloc() function. In C,
malloc() is used to allocate a given number of bytes of memory. For the most part, using malloc() is
simple and straightforward. The malloc() function still exists in C++, but we recommend avoiding it.
The main advantage of new over malloc() is that new doesn’t just allocate memory, it constructs objects.
A similar difference exists between the free() function and the delete function. With free(), the
object”s destructor will not be called. With delete, the destructor will be called and the object will be properly cleaned up.
2008年6月27日星期五
malloc vs new
訂閱:
張貼意見 (Atom)
0 意見:
張貼意見