和+, -, *, /差不多,都是语言内部机制。可能是用C和汇编写的,直接操作硬件或操作系统。
回复:
晕,上面的五级的经理,看你级别挺高,怎么不给个像样的答案呢?说的跟算命先生似的。什么也没有。。
确实是说得简单了。
不同编译器的实现是不同的,现在给一个实现,只有一部分,其他的自己看gcc的源代码。
#include
#include
#include
#include "new"
using std::new_handler;
using std::bad_alloc;
#if _GLIBCXX_HOSTED
using std::malloc;
#else
extern "C" void *malloc (std::size_t);
#endif
extern new_handler __new_handler;
_GLIBCXX_WEAK_DEFINITION void *
operator new (std::size_t sz) throw (std::bad_alloc)
{
void *p;
/* malloc (0) is unpredictable; avoid it. */
if (sz == 0)
sz = 1;
p = (void *) malloc (sz);
while (p == 0)
{
new_handler handler = __new_handler;
if (! handler)
#ifdef __EXCEPTIONS
throw bad_alloc();
#else
std::abort();
#endif
handler ();
p = (void *) malloc (sz);
}
return p;
}
晕,上面的五级的经理,看你级别挺高,怎么不给个像样的答案呢?说的跟算命先生似的。什么也没有。。