> This page is for version 4.3.
> For other versions, use one of these documentation indexes:
> - 4.6 (Latest) (default): https://docs.nvidia.com/holoscan/sdk-user-guide/4-6-latest/llms.txt
> - ltsb-2.0: https://docs.nvidia.com/holoscan/sdk-user-guide/ltsb-2-0/llms.txt
> - 4.5: https://docs.nvidia.com/holoscan/sdk-user-guide/4-5/llms.txt
> - 4.4: https://docs.nvidia.com/holoscan/sdk-user-guide/4-4/llms.txt
> - 4.3: https://docs.nvidia.com/holoscan/sdk-user-guide/4-3/llms.txt
> - Archives: https://docs.nvidia.com/holoscan/sdk-user-guide/archives/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::utils::cuda::DeviceBuffer

> CUDA Device Buffer Class.

CUDA Device [Buffer](buffer) Class.

```cpp showLineNumbers={false}
#include <holoscan/utils/cuda/buffer.hpp>
```

**Inherits from:** `holoscan::utils::cuda::Buffer` (public)

---

## Constructors

### DeviceBuffer \[#devicebuffer]

#### Construction with size

```cpp showLineNumbers={false}
holoscan::utils::cuda::DeviceBuffer::DeviceBuffer(
    size_t size,
    int device_id = 0
)
```

Construction with size.

**Parameters**

**`size`** `size_t`

Memory size to be allocated in bytes

---

**`device_id`** `int` — default: 0

GPU device ID, defaults to 0

---

#### Deleted overloads

The following overloads are deleted to prevent misuse:

```cpp showLineNumbers={false}
holoscan::utils::cuda::DeviceBuffer::DeviceBuffer(const DeviceBuffer &) = delete;
holoscan::utils::cuda::DeviceBuffer::DeviceBuffer(DeviceBuffer &&) = delete;
```

### Destructor \[#destructor]

### \~DeviceBuffer

```cpp showLineNumbers={false}
holoscan::utils::cuda::DeviceBuffer::~DeviceBuffer()
```

Destructor.

---

## Assignment operators

### operator= \[#operator\_assign]

#### Deleted overloads

The following overloads are deleted to prevent misuse:

```cpp showLineNumbers={false}
DeviceBuffer & holoscan::utils::cuda::DeviceBuffer::operator=(const DeviceBuffer &) = delete;
DeviceBuffer & holoscan::utils::cuda::DeviceBuffer::operator=(DeviceBuffer &&) = delete;
```

---

## Methods

### data \[#data]

```cpp showLineNumbers={false}
void * holoscan::utils::cuda::DeviceBuffer::data() override
```

[Buffer](buffer) class virtual members implemented by this class.

### size \[#size]

```cpp showLineNumbers={false}
size_t holoscan::utils::cuda::DeviceBuffer::size() const override
```

Get the size of the allocated buffer in elements.

**Returns:** size in elements

### get\_bytes \[#getbytes]

```cpp showLineNumbers={false}
size_t holoscan::utils::cuda::DeviceBuffer::get_bytes() const override
```

Get the bytes allocated.

**Returns:** allocated bytes

### resize \[#resize]

```cpp showLineNumbers={false}
void holoscan::utils::cuda::DeviceBuffer::resize(
    size_t number_of_elements
) override
```

Resize the underlying buffer.

**Parameters**

**`number_of_elements`** `size_t`

Number of elements to be resized with

---

### host\_data \[#hostdata]

```cpp showLineNumbers={false}
void * holoscan::utils::cuda::DeviceBuffer::host_data(
    cudaStream_t stream = 0
)
```

Copies data from device to host after allocating the host memory.

### get\_datatype \[#getdatatype]

```cpp showLineNumbers={false}
BufferDataType holoscan::utils::cuda::DeviceBuffer::get_datatype() const
```

Get the datatype.

**Returns:** datatype

### get\_device \[#getdevice]

```cpp showLineNumbers={false}
int holoscan::utils::cuda::DeviceBuffer::get_device() const
```

Get the device ID.

**Returns:** device ID

---

## Member variables

| Name           | Type             | Description                             |
| -------------- | ---------------- | --------------------------------------- |
| `size_`        | `size_t`         |                                         |
| `capacity_`    | `size_t`         |                                         |
| `buffer_`      | `void *`         |                                         |
| `host_buffer_` | `void *`         |                                         |
| `allocator_`   | `CudaAllocator`  |                                         |
| `free_`        | `CudaFree`       |                                         |
| `data_type_`   | `BufferDataType` | Datatype of the elements in the buffer. |
| `device_id_`   | `int`            | Device ID.                              |