---
title: "fromBlob"
sidebar_label: "fromBlob"
description: "Kotlin binding reference: fromBlob."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

//[clika-runtime](../../../index.md)/[io.clika.runtime](../index.md)/[Tensors](index.md)/[fromBlob](fromBlob.md)

# fromBlob

[common]\
fun [fromBlob](fromBlob.md)(buffer: &lt;Error class: unknown class&gt;, shape: [LongArray](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html), dtype: [DType](../DType/index.md) = DType.FLOAT32, where: [Placement](../Placement/index.md)? = null, deleter: [VoidCallback](../VoidCallback/index.md)? = null): [Tensor](../Tensor/index.md)

Wrap memory the application owns, without copying: [buffer](fromBlob.md) must be a DIRECT `ByteBuffer` (`allocateDirect`, the one JVM buffer with a stable native address) holding [shape](fromBlob.md) elements of [dtype](fromBlob.md) in row-major order from its position 0. With no [deleter](fromBlob.md) the tensor BORROWS the buffer, which the returned tensor keeps referenced while it lives (a view derived from it does not: keep the buffer alive for as long as any view is in use); with a [deleter](fromBlob.md) the tensor ADOPTS it, and the deleter runs exactly once, when the last reference drops (on whichever thread that happens). Writes through the buffer are visible through the tensor: it is the same memory. A buffer smaller than the shape needs is refused.

```kotlin
val buf = ByteBuffer.allocateDirect(8 * 4).order(ByteOrder.nativeOrder())
val view = Tensors.fromBlob(buf, longArrayOf(8))          // borrowed
val owned = Tensors.fromBlob(buf, longArrayOf(8), deleter = VoidCallback {
    println("released")                                    // adopted
})
```