allocate method
DVPlatformMemory
allocate({
- int? gigabytes,
- int? megabytes,
- DVMemoryProfile? profile,
- DVSize? segment,
- bool? touchPages,
Creates an arena, applying the configured defaults and the target's ceiling, and registers it.
An explicit segment or touchPages wins over configuration; a size
larger than the target's ceiling is capped to it, and the arena records
DV-MEMORY-001 saying so.
Implementation
DVPlatformMemory allocate({
int? gigabytes,
int? megabytes,
DVMemoryProfile? profile,
DVSize? segment,
bool? touchPages,
}) {
if (gigabytes != null && megabytes != null) {
throw ArgumentError('pass gigabytes or megabytes, not both');
}
final DVMemoryTarget target = _target ?? DVMemoryTarget.current;
final String deviceProfile = _deviceProfile ?? _profileDefine;
final DVMemorySettings s = _config.resolve(
target,
deviceProfile: deviceProfile,
);
final DVSize? asked = gigabytes != null
? DVSize.gb(gigabytes)
: megabytes != null
? DVSize.mb(megabytes)
: s.budget;
final DVSize chosenSegment =
segment ??
(profile != null && !s.segmentConfigured ? profile.segment : s.segment);
final bool touch =
touchPages ??
(_config.touchPagesRefusedOn(target, deviceProfile: deviceProfile)
? true
: s.touchPages);
final DVPlatformMemory arena = DVPlatformMemory.configured(
asked: asked,
profile: profile,
segment: chosenSegment,
touchPages: touch,
target: target,
backing: _backing ?? dvDefaultMemoryBacking(),
ceiling: s.ceiling,
ceilingSource: s.ceilingSource,
id: _nextId++,
);
_live.add(WeakReference<DVPlatformMemory>(arena));
return arena;
}