The AdaptEvaluationUnit class enables a MUFL application (compiled MUFL code, .muflo file) to be loaded either from the file or from the buffer. It implements the same memory management API as AdaptPacketContext (AdaptPacketContext) and AdaptValue (AdaptValue). The loaded MUFL application must be deleted either manually or using AdaptObjectLifetime (Finalize).
Hierarchy
-
↳
AdaptEvaluationUnit
Table of contents
Accessors
Methods
Accessors
lifetime
• get
lifetime(): undefined
| AdaptObjectLifetime
Returns
undefined
| AdaptObjectLifetime
Inherited from
AdaptObject.lifetime
Defined in
common/dist/memory_management/adapt_object_lifetime.d.ts:54
• set
lifetime(lt
): void
Parameters
Name | Type |
---|---|
lt |
undefined | AdaptObjectLifetime |
Returns
void
Inherited from
AdaptObject.lifetime
Defined in
common/dist/memory_management/adapt_object_lifetime.d.ts:55
Methods
Attach
▸ Attach(lt?
): AdaptEvaluationUnit
Attach an object to the given lifetime object.
When a lifetime object has already been defined, first detach the object from the previous lifetime object, then attach it to the new one.
Example
AdaptEnvironment.InitializeAsync().then(() => {
const lifetime = new AdaptObjectLifetime();
const lifetime1 = new AdaptObjectLifetime();
const value = new AdaptValue(lifetime, 5);
value.Attach(lifetime1);
lifetime.Finalize(); // value is not destroyed by this call
lifetime1.Finalize(); // value is destroyed
})
Parameters
Name | Type | Description |
---|---|---|
lt? |
AdaptObjectLifetime |
Lifetime to attach object to |
Returns
Inherited from
Defined in
common/dist/memory_management/adapt_object_lifetime.d.ts:76
Clone
▸ Clone(lifetime?
): AdaptEvaluationUnit
Clone the AdaptEvaluationUnit so the cloned value is not destoyed when the original is.
Throws
An error if ADAPT is not initialized (see Initialize or InitializeAsync)
Example
AdaptEnvironment.InitializeAsync().then(() => {
const unit: AdaptEvaluationUnit; // assume this application has been loaded from either file or buffer
const unitClone = unit.Clone(undefined);
unit.Destroy();
// unitClone can be used here. It is not destroyed
})
Example
Missing clone
AdaptEnvironment.InitializeAsync().then(() => {
const unit: AdaptEvaluationUnit; // assume this application has been loaded from either file or buffer
const unitCopyRef = unit; // copy just the TypeScript reference to the object, instead of making a deep copy using the Clone method.
unit.Destroy();
// unitCopyRef can't be used here because the C++ object has been deleted on the previous line and unitCopyRef no longer points to a valid object
})
Parameters
Name | Type |
---|---|
lifetime? |
AdaptObjectLifetime |
Returns
The cloned AdaptEvaluationUnit
Overrides
Defined in
Destroy
▸ Destroy(): void
Destroy the C++ object. After calling this method, the object reference is no longer valid and, thus, can’t be used.
Example
AdaptEnvironment.InitializeAsync().then(() => {
const lifetime = new AdaptObjectLifetime();
const value = new AdaptValue(lifetime, 5);
const anotherValue = value;
const valueCloned = value.Clone(undefined);
value.Destroy();
// Both `value` and `anotherValue` can't be used because they are pointing to the same C++ object that has been deleted.
// However, `valueCloned` is valid because it points to another (cloned) C++ object.
valueCloned.Destroy();
lifetime.Finalize();
})
Returns
void
Inherited from
Defined in
common/dist/memory_management/adapt_object_lifetime.d.ts:34
Detach
▸ Detach(): AdaptEvaluationUnit
Detach the value from the lifetime object.
Example
AdaptEnvironment.InitializeAsync().then(() => {
const lifetime = new AdaptObjectLifetime();
const value = new AdaptValue(lifetime, 5);
value.Detach(); // value must be destroyed manually now
lifetime.Finalize(); // value is not destroyed by this call
value.Destroy();
})
Returns
Inherited from
Defined in
common/dist/memory_management/adapt_object_lifetime.d.ts:92
LoadFromContents
▸ Static
LoadFromContents(lt
, contents
): AdaptEvaluationUnit
Load the MUFL application from the binary buffer.
Throws
An error if the application loading failed (invalid content, etc.) or if ADAPT is not initialized (see Initialize or InitializeAsync).
Example
AdaptEnvironment.InitializeAsync().then(() => {
const pathToFile = "this/is/path/to/file.muflo";
const contents = fs.readFileSync(pathToFile);
const lifetime = new AdaptObjectLifetime();
const unit = AdaptEvaluationUnit.LoadFromContents(lifetime, contents);
lifetime.Finalize();
})
Parameters
Name | Type | Description |
---|---|---|
lt |
undefined | AdaptObjectLifetime |
The lifetime object to attach the created application to. If undefined is passed, the application must be destroyed (see Destroy) manually. |
contents |
Buffer |
The binary content produced by compiling the MUFL source code |
Returns
A MUFL application
Defined in
LoadFromFile
▸ Static
LoadFromFile(lt
, fileName
): AdaptEvaluationUnit
Load the MUFL application from the (.muflo binary) file produced by compiling MUFL source code.
Throws
An error if ADAPT is not initialized (see Initialize or InitializeAsync). Error if application loading failed (invalid path, invalid file content, etc.)
Example
AdaptEnvironment.InitializeAsync().then(() => {
const pathToFile = "this/is/path/to/file.muflo";
const lifetime = new AdaptObjectLifetime();
const unit = AdaptEvaluationUnit.LoadFromFile(lifetime, pathToFile);
lifetime.Finalize();
})
Parameters
Name | Type | Description |
---|---|---|
lt |
undefined | AdaptObjectLifetime |
The lifetime object to attach the created application to. If undefined is passed, the application must be destroyed (see Destroy) manually. |
fileName |
string |
The path to the file |
Returns
A MUFL application