---
title: malloc
description: "内存分配。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0020.html
sourcePath: /source/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0020.html
indexId: a7ae12c929a1aa7695dd4ba07ace378fc127b326673877aa223245eaee0229bf74
---
# malloc

内存分配。

void *malloc(size_t size);

#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| size | 申请内存的字节数。 | 非负数 | 输入 |


#### 返回值

- 成功：返回指向分配内存的指针。
- 失败：返回空指针。


#### 示例

```
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "kqmalloc.h"
#define KQMALLOC_TEST_LEN 10
void MallocExample()
{
int8_t *res = (int8_t *)malloc(KQMALLOC_TEST_LEN);
if (res == NULL) {
printf("res is null\n");
} else {
printf("malloc pointer address: %lx\n", res);
free(res);
}
}
int main(void) {
MallocExample();
return 0;
}
```

运行结果：

```
malloc pointer address: ffff97ae8174
```
