new和delete其实只是操作符而已,uefi没有提供我们可以自己写
__inline void * operator new (size_t Size)
{
void *RetVal;
EFI_STATUS Status;
if(0 == Size)
{
return NULL;
}
Status = gBS->AllocatePool(EfiLoaderData, (UINTN)Size, &RetVal);
if(EFI_SUCCESS == Status)
{
return NULL;
}
return RetVal;
}
__inline void * operator new [](size_t cb)
{
void *res = operator new (cb);
return res;
}
__inline void operator delete (void *p)
{
if(NULL != p)
{
gBS->FreePool(p);
}
}
__inline void operator delete[] (void *p)
{
operator delete(p);
}
加上这段代码,uefi就可以使用new和delete了