allocate method

Pointer allocate(
  1. int size
)

Implementation

Pointer allocate(int size) {
  for (int i = 0; i < freeBlocks.length; i++) {
    final block = freeBlocks[i];
    if (block >= size) {
      freeBlocks.removeAt(i);
      return Pointer(block, size);
    }
  }
  final addr = _malloc(size);
  if (addr == 0) {
    throw ArgumentError("Number of bytes cannot be satisfied.");
  }
  return Pointer(addr, size);
}