allocate<T extends NativeType> method
Allocates byteCount bytes of of unitialized memory on the native heap.
For POSIX-based systems, this uses malloc. On Windows, it uses
CoTaskMemAlloc.
Throws an ArgumentError if the number of bytes or alignment cannot be satisfied.
Implementation
// TODO: Stop ignoring alignment if it's large, for example for SSE data.
@override
Pointer<T> allocate<T extends NativeType>(int byteCount, {int? alignment}) {
Pointer<T> result;
if (Platform.isWindows) {
result = winCoTaskMemAlloc(byteCount).cast();
} else {
result = posixMalloc(byteCount).cast();
}
if (result.address == 0) {
throw ArgumentError('Could not allocate $byteCount bytes.');
}
return result;
}