XFusion API v1.3.0
载入中...
搜索中...
未找到
xf_heap.c 文件参考

提供给外界调用的malloc API 更多...

#include "xf_heap.h"
#include "xf_alloc.h"
xf_heap.c 的引用(Include)关系图:

浏览源代码.

结构体

struct  _heap_t
 

类型定义

typedef struct _heap_t heap_t
 

函数

static void * _xf_malloc (unsigned int size)
 
static void _xf_free (void *pv)
 
static unsigned int _xf_heap_get_free_size (void)
 
static unsigned int _xf_heap_get_min_ever_free_size (void)
 
int xf_heap_api_redirect (const xf_heap_api_t *api)
 重新定义内存管理接口
 
int xf_heap_init (const xf_heap_region_t *const regions)
 内存初始化。
 
int xf_heap_uninit (void)
 内存反初始化。
 
void * xf_malloc (unsigned int size)
 申请内存。
 
void xf_free (void *pv)
 释放内存。
 
unsigned int xf_heap_get_free_size (void)
 获取内存总空闲大小。
 
unsigned int xf_heap_get_min_ever_free_size (void)
 获取曾经最小的空闲内存块。
 

变量

static heap_t s_heap
 
static const xf_heap_api_ts_heap_api = {0}
 
static const xf_heap_api_t _heap_api
 

详细描述

提供给外界调用的malloc API

作者
cangyu (sky.k.nosp@m.irto.nosp@m.@qq.c.nosp@m.om)
版本
0.1
日期
2024-07-09
作者
cangyu (sky.k.nosp@m.irto.nosp@m.@qq.c.nosp@m.om)
注解
加入了计算剩余大小,添加了线程安全
版本
0.1
日期
2023-11-15

在文件 xf_heap.c 中定义.

类型定义说明

◆ heap_t

typedef struct _heap_t heap_t

函数说明

◆ _xf_malloc()

static void * _xf_malloc ( unsigned int  size)
static

在文件 xf_heap.c143 行定义.

◆ _xf_free()

static void _xf_free ( void *  pv)
static

在文件 xf_heap.c163 行定义.

◆ _xf_heap_get_free_size()

static unsigned int _xf_heap_get_free_size ( void  )
static

在文件 xf_heap.c178 行定义.

◆ _xf_heap_get_min_ever_free_size()

static unsigned int _xf_heap_get_min_ever_free_size ( void  )
static

在文件 xf_heap.c194 行定义.

◆ xf_heap_api_redirect()

int xf_heap_api_redirect ( const xf_heap_api_t api)

重新定义内存管理接口

参数
api内存管理接口
返回
int
  • XF_HEAP_FAIL 参数定义错误
  • XF_HEAP_OK 设置成功

在文件 xf_heap.c65 行定义.

◆ xf_heap_init()

int xf_heap_init ( const xf_heap_region_t *const  regions)

内存初始化。

参数
regions注册不同内存区域。
注解
regions 数组最后一个元素必须是 {}(0数组)。内部以此作为数组结束标志。
该函数只能在 xf_malloc 之前调用。
返回
int
  • 0 设置成功
  • -1 设置失败

在文件 xf_heap.c76 行定义.

◆ xf_heap_uninit()

int xf_heap_uninit ( void  )

内存反初始化。

返回
int
  • 0 设置成功
  • -1 设置失败

在文件 xf_heap.c93 行定义.

变量说明

◆ s_heap

heap_t s_heap
static
初始值:
= {
.init = 0,
.free_bytes = 0,
.min_ever_free_bytes_remaining = 0,
.func = {
.malloc = xf_heap_malloc,
.free = xf_heap_free,
.init = xf_heap_region,
.get_block_size = xf_heap_get_block_size,
}
}
void xf_heap_free(void *pv)
带内存管理的内存释放函数。
Definition xf_alloc.c:119
unsigned int xf_heap_get_block_size(void *pv)
获取内存块的实际大小。
Definition xf_alloc.c:204
unsigned int xf_heap_region(const xf_heap_region_t *const heap_regions)
内存注册,需要在使用 xf_heap_malloc 之前注册。
Definition xf_alloc.c:141
void * xf_heap_malloc(unsigned int size)
带内存管理的内存申请函数。
Definition xf_alloc.c:60
#define XF_HEAP_LOCK_PTR

在文件 xf_heap.c40 行定义.

◆ s_heap_api

const xf_heap_api_t* s_heap_api = {0}
static

在文件 xf_heap.c53 行定义.

◆ _heap_api

const xf_heap_api_t _heap_api
static
初始值:
= {
.malloc = _xf_malloc,
.free = _xf_free,
.get_free_size = _xf_heap_get_free_size,
.get_min_ever_free_size = _xf_heap_get_min_ever_free_size
}
static void _xf_free(void *pv)
Definition xf_heap.c:163
static unsigned int _xf_heap_get_min_ever_free_size(void)
Definition xf_heap.c:194
static unsigned int _xf_heap_get_free_size(void)
Definition xf_heap.c:178
static void * _xf_malloc(unsigned int size)
Definition xf_heap.c:143

在文件 xf_heap.c54 行定义.