Show / Hide Table of Contents

# Class OrtMemoryInfo

This class encapsulates and most of the time owns the underlying native OrtMemoryInfo instance. Instance returned from OrtAllocator will not own OrtMemoryInfo, the class must be disposed regardless.

Use this class to query and create OrtAllocator instances so you can pre-allocate memory for model inputs/outputs and use it for binding. Instances of the class can also used to created OrtValues bound to pre-allocated memory. In that case, the instance of OrtMemoryInfo contains the information about the allocator used to allocate the underlying memory.

##### Inheritance

System.Object
OrtMemoryInfo

###### Namespace: Microsoft.ML.OnnxRuntime

###### Assembly: cs.temp.dll.dll

##### Syntax

    public class OrtMemoryInfo : SafeHandle

### Constructors

#### OrtMemoryInfo(Byte[], OrtAllocatorType, Int32, OrtMemType)

Create an instance of OrtMemoryInfo according to the specification Memory info instances are usually used to get a handle of a native allocator that is present within the current inference session object. That, in turn, depends of what execution providers are available within the binary that you are using and are registered with Add methods.

##### Declaration

    public OrtMemoryInfo(byte[] utf8AllocatorName, OrtAllocatorType allocatorType, int deviceId, OrtMemType memoryType)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Byte[] | utf8AllocatorName | Allocator name. Use of the predefined above.
OrtAllocatorType | allocatorType | Allocator type
System.Int32 | deviceId | Device id
OrtMemType | memoryType | Memory type

#### OrtMemoryInfo(String, OrtAllocatorType, Int32, OrtMemType)

Create an instance of OrtMemoryInfo according to the specification.

##### Declaration

    public OrtMemoryInfo(string allocatorName, OrtAllocatorType allocatorType, int deviceId, OrtMemType memoryType)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | allocatorName | Allocator name
OrtAllocatorType | allocatorType | Allocator type
System.Int32 | deviceId | Device id
OrtMemType | memoryType | Memory type

### Fields

#### allocatorCPU

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

##### Declaration

    public static readonly byte[] allocatorCPU

##### Field Value

Type | Description
--- | ---
System.Byte[] |

#### allocatorCUDA

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

##### Declaration

    public static readonly byte[] allocatorCUDA

##### Field Value

Type | Description
--- | ---
System.Byte[] |

#### allocatorCUDA_PINNED

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

##### Declaration

    public static readonly byte[] allocatorCUDA_PINNED

##### Field Value

Type | Description
--- | ---
System.Byte[] |

### Properties

#### DefaultInstance

Default CPU based instance

##### Declaration

    public static OrtMemoryInfo DefaultInstance { get; }

##### Property Value

Type | Description
--- | ---
OrtMemoryInfo | Singleton instance of a CpuMemoryInfo

#### Id

Returns device ID

##### Declaration

    public int Id { get; }

##### Property Value

Type | Description
--- | ---
System.Int32 | returns integer Id value

#### IsInvalid

Overrides SafeHandle.IsInvalid

##### Declaration

    public override bool IsInvalid { get; }

##### Property Value

Type | Description
--- | ---
System.Boolean | returns true if handle is equal to Zero

#### Name

Name of the allocator associated with the OrtMemoryInfo instance

##### Declaration

    public string Name { get; }

##### Property Value

Type | Description
--- | ---
System.String |

### Methods

#### Equals(OrtMemoryInfo)

Compares this instance with another

##### Declaration

    public bool Equals(OrtMemoryInfo other)

##### Parameters

Type | Name | Description
--- | --- | ---
OrtMemoryInfo | other | OrtMemoryInfo to compare to

##### Returns

Type | Description
--- | ---
System.Boolean | true if instances are equal according to OrtCompareMemoryInfo.

#### Equals(Object)

Overrides System.Object.Equals(object)

##### Declaration

    public override bool Equals(object obj)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Object | obj | object to compare to

##### Returns

Type | Description
--- | ---
System.Boolean | true if obj is an instance of OrtMemoryInfo and is equal to this

#### GetAllocatorType()

Fetches allocator type from the underlying OrtAllocator

##### Declaration

    public OrtAllocatorType GetAllocatorType()

##### Returns

Type | Description
--- | ---
OrtAllocatorType | Returns allocator type

#### GetHashCode()

Overrides System.Object.GetHashCode()

##### Declaration

    public override int GetHashCode()

##### Returns

Type | Description
--- | ---
System.Int32 | integer hash value

#### GetMemoryType()

The below 2 are really properties but naming them is a challenge as names would conflict with the returned type. Also, there are native calls behind them so exposing them as Get() would be appropriate.

##### Declaration

    public OrtMemType GetMemoryType()

##### Returns

Type | Description
--- | ---
OrtMemType | OrtMemoryType for the instance

#### ReleaseHandle()

Overrides SafeHandle.ReleaseHandle() to properly dispose of the native instance of OrtMmeoryInfo

##### Declaration

    protected override bool ReleaseHandle()

##### Returns

Type | Description
--- | ---
System.Boolean | always returns true