<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreAI",
  "identifier" : "/documentation/CoreAI/NDArrayDescriptor/minimumByteCount",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Core AI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime17NDArrayDescriptorV16minimumByteCountSivp"
  },
  "title" : "minimumByteCount"
}
-->

# minimumByteCount

The minimum number of bytes needed for storage with this
descriptor’s shape and preferred strides.

```
var minimumByteCount: Int { get }
```

## Discussion

The shape/strides/scalarType of this descriptor are used to compute the addressable byte range of the layout, and
the size of that range is returned as the minimum size a backing storage would need to be to contain the ndArray.

In most cases it is preferred to make `NDArray` instances which handle creating the allocations for you, but in circumstances where you
need to manually handle your allocations, this property can be useful to help you find how large of a storage to allocate.

```swift
let metalDevice: any MTLDevice = ...
let functionDescriptor = model.functionDescriptor(for: "main")
guard case .ndArray(let ndArrayDescriptor) = functionDescriptor.inputDescriptor(of: "dynamic_shape_input") else {
  // Handle input not found or not ndArray
}

// Assuming that the descriptor is known to have static shapes. If it had dynamic shapes it'd be
// required to first call `resolvingDynamicDimensions`.
let byteCount = ndArrayDescriptor.minimumByteCount
let metalBuffer = metalDevice.makeBuffer(length: byteCount)!

// Later at inference time... manual allocations can be provided by making views from them.
let view = NDArray.RawView(
  metalBuffer: metalBuffer,
  byteOffset: 0,
  shape: ndArrayDescriptor.shape,
  scalarType: ndArrayDescriptor.scalarType,
  strides: ndArrayDescriptor.preferredStrides
)
var inputs = InferenceFunction.Inputs()
inputs.insert(view, for: "myInput")
var outputs = inferenceFunction.run(inputs: inputs)
```

`hasDynamicShape` must be false when accessing this property, as the size is unknown if there are dynamic shapes.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)