---
title: TensorBuffer
description: "TensorBuffer的构造函数，用来创建TensorBuffer对象，根据传入的不同参数可选用不同的构造函数。"
url: https://www.hiascend.com/document/detail/zh/Atlas200IDKA2DeveloperKit/latest/Application%20Development%20Guide/msadg/mxvisionug_0454.html
sourcePath: /source/zh/Atlas200IDKA2DeveloperKit/23.0.RC2/Application Development Guide/msadg/mxvisionug_0454.html
indexId: aaa241ba9c01df8e5492d342381743ae175bd36021c3b2ccefe050f94bab7776102
---
# TensorBuffer

#### 函数功能

TensorBuffer的构造函数，用来创建TensorBuffer对象，根据传入的不同参数可选用不同的构造函数。


#### 函数原型

```
TensorBuffer();
```

```
TensorBuffer(uint32_t size, MemoryData::MemoryType type, int32_t deviceId);
```

```
TensorBuffer(uint32_t size, int32_t deviceId);
```

```
TensorBuffer(uint32_t size);
```

```
TensorBuffer(void *ptr, uint32_t size, MemoryData::MemoryType type = MemoryData::MemoryType::MEMORY_HOST_NEW, int32_t deviceId = -1);
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| ptr | 输入 | 内存指针。 |
| size | 输入 | 内存大小。 |
| type | 输入 | 用于构造TensorBuffer对象的内存类型。 |
| deviceId | 输入 | 用于构造TensorBuffer对象的参数，int类型数据，设备编号。 |
