STD_NEW_ARRAY

STD_NEW_ARRAY(alloc, Type, count)

功能

  • 该宏使用Allocator alloc实例分配内存以创建Type类型对象的数组。类Type的默认构造函数将被调用。

alloc

  • 参数alloc是一个Allocator实例。该Allocator要求支持以下concept:
class Allocator
{
public:
    template <class Type>
    Type* newArray(size_t count, Type* zero); // Release版本调用这个
 
    template <class Type>
    Type* newArray(size_t count, Type* zero, LPCSTR szFile, int nLine);
        // Debug版本会调用这个
};

Type

  • 参数Type是指要new的对象的类型。

count

  • 参数count是指要new的对象数组的元素个数。

返回值

  • 返回一个类型为Type*的对象数组指针。

举例

std::AutoFreeAlloc alloc;
Type* objArray = STD_NEW_ARRAY(alloc, Type, 100);

相关参考

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License