allocate<T extends NativeType> 抽象方法
在本地堆上分配 `byteCount
` 字节的内存。
如果提供了 `alignment
`,则分配的内存至少将对齐到 `alignment
` 字节数。
为了分配 `sizeOf<T>()
` 字节的多倍,请直接将分配器作为函数调用:`allocator<T>(count)`(有关详细信息,请参阅 AllocatorAlloc.call)。
// This allocates two bytes. If you intended two Int32's, this is an
// error.
allocator.allocate<Int32>(2);
// This allocates eight bytes, which is enough space for two Int32's.
// However, this is not the idiomatic way.
allocator.allocate<Int32>(sizeOf<Int32>() * 2);
// The idiomatic way to allocate space for two Int32 is to call the
// allocator directly as a function.
allocator<Int32>(2);
如果字节数或对齐无法满足,将抛出 `ArgumentError`。
实现
Pointer<T> allocate<T extends NativeType>(int byteCount, {int? alignment});