---
title: 函数：malloc_host_with_cfg
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/runtimeapi/aclpythondevg_01_1061.html
sourcePath: /source/zh/canncommercial/900/API/runtimeapi/aclpythondevg_01_1061.html
indexId: e2733828edf6969634b18d7b4fcaf5341146ff9739b0eda21a1633f9ed584cec71
---
# 函数：malloc_host_with_cfg

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |
| Atlas 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | √ |


#### 功能说明

申请Host内存（该内存是锁页内存），由系统保证内存首地址64字节对齐。与acl.rt.malloc_host接口相比，本接口在申请内存时，还可以指定内存相关的配置信息。

针对 Ascend RC 形态、Control CPU开放形态，Host与Device是合一的，所以申请Host内存也等同于申请Device内存。此外，申请内存时，按普通页申请。如果需要64字节对齐的首地址，用户需自行处理对齐问题。


#### 函数原型

- C函数原型
  1 aclError aclrtMallocHostWithCfg(void **ptr, uint64_t size, aclrtMallocConfig *cfg)

- python函数
  1 host_ptr, ret= acl.rt.malloc_host_with_cfg(size, cfg)


#### 参数说明

| 参数名 | 说明 |
| --- | --- |
| size | int，申请内存的大小，单位Byte。size不能为0。 |
| cfg | dict，内存配置信息。不指定配置时，此处可传空字典，具体请参见aclrtMallocConfig。 |


#### 返回值说明

| 返回值 | 说明 |
| --- | --- |
| host\_ptr | int，指向Host上已分配内存的指针地址。 |
| ret | int，错误码，返回0表示成功，返回其它值表示失败。 |
