[ILNumerics Computing Engine]
Namespace: ILNumerics
Assembly: ILNumerics.Computing (in ILNumerics.Computing.dll) Version: 5.5.0.0 (5.5.7503.3146)
public static MemoryHandle New<T>( long elementCount, uint deviceIndex = 0, bool clear = false )
Parameters
- elementCount
- Type: SystemInt64
Number of elements which must at least fit into the memory region. - deviceIndex (Optional)
- Type: SystemUInt32
[Optional] Index of the device owning the memory. Default: 0 is the host device. - clear (Optional)
- Type: SystemBoolean
[Optional] Flag determining whether the memory should be initialized to zero. Default: do not clear.
Type Parameters
- T
- Element type, specifies the type and size of elements.
Return Value
Type: MemoryHandleMemory handle to a memory region or an managed array accoring to the provided element type and device.
Exception | Condition |
---|---|
InvalidOperationException | when trying to access either of the Pointer or the HostArray properties on handles of invalid types. |
This function supports the utilization of memory regions in a C style manner: user have to manage memory explicitly and manually. Instead of using this function it is recommended to use the common ILNumerics array creation functions to create and work with ILNumerics arrays. which do not require to create, clean up or to reuse memory manually. ILNumerics function rules do all this automatically. Thus, manual memory management is left for very few special situations only.
Depending on the type category the memory handle returned references one of the following memory types:
- T is struct / ValueType: memory is allocated on the unmanaged heap. There is no inherent size limitation. Access to the memory is done by means of the Pointer property. Users are responsible to correctly deal with such pointers. All risks of unsafe code apply.
- T is class / reference type: the function allocates a Array on the managed heap. Access is done by first casting the memory handle returned to the concrete type of ManagedHostHandleT and then using the HostArray property to acquire the T[] array.
Attempting to access the HostArray on a native handle generates an exception.
Attempting to access the Pointer on a ManagedHostHandle{T} generates an exception.
MemoryHandles are critical handles. Disposal is guaranteed by critical execution regions and the GC. However, users should dispose the handle to free the memory region immediately after use. Use free``1(MemoryHandle, UInt32, Boolean) for disposing memory handles.
[ILNumerics Computing Engine]