DynamicLibrary.fromModule constructor

  1. @extra
DynamicLibrary.fromModule(
  1. Module module, [
  2. MemoryRegisterMode registerMode = MemoryRegisterMode.onlyIfGlobalNotSet
])

Creates a new instance based on the given module.

While for each DynamicLibrary a new Memory object is created, the Memory objects share the backing memory if they are created based on the same module.

The registerMode parameter can be used to control if the newly created Memory object should be registered as Memory.global.

Implementation

@extra
factory DynamicLibrary.fromModule(Module module,
    [MemoryRegisterMode registerMode =
        MemoryRegisterMode.onlyIfGlobalNotSet]) {
  Memory memory = createMemory(module);
  switch (registerMode) {
    case MemoryRegisterMode.yes:
      Memory.global = memory;
      break;
    case MemoryRegisterMode.no:
      break;
    case MemoryRegisterMode.onlyIfGlobalNotSet:
      if (Memory.global == null) {
        Memory.global = memory;
      }
      break;
  }
  return new DynamicLibrary._(memory);
}