Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5e9909a1
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5e9909a1
编写于
11月 08, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
5a17541b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
157 addition
and
1 deletion
+157
-1
include/util/mallocator.h
include/util/mallocator.h
+57
-0
source/dnode/vnode/impl/inc/vnodeInt.h
source/dnode/vnode/impl/inc/vnodeInt.h
+0
-1
source/util/src/arenaAllocator.c
source/util/src/arenaAllocator.c
+14
-0
source/util/src/heapAllocator.c
source/util/src/heapAllocator.c
+86
-0
未找到文件。
include/util/
amalloc
.h
→
include/util/
mallocator
.h
浏览文件 @
5e9909a1
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_
AMALLOC
_H_
#define _TD_
AMALLOC
_H_
#ifndef _TD_
MALLOCATOR
_H_
#define _TD_
MALLOCATOR
_H_
#include "os.h"
...
...
@@ -22,31 +22,36 @@
extern
"C"
{
#endif
#define AMALLOC_APIS \
void *(*malloc)(void *, size_t size); \
void *(*calloc)(void *, size_t nmemb, size_t size); \
void *(*realloc)(void *, size_t size); \
void (*free)(void *ptr);
typedef
struct
SMemAllocator
SMemAllocator
;
#define MALLOCATOR_APIS \
void *(*malloc)(SMemAllocator *, size_t size); \
void *(*calloc)(SMemAllocator *, size_t nmemb, size_t size); \
void *(*realloc)(SMemAllocator *, size_t size); \
void (*free)(SMemAllocator *, void *ptr); \
size_t (*usage)(SMemAllocator *);
// Interfaces to implement
typedef
struct
{
AMALLOC
_APIS
MALLOCATOR
_APIS
}
SMemAllocatorIf
;
typedef
struct
{
void
*
impl
;
AMALLOC_APIS
}
SMemAllocator
;
struct
SMemAllocator
{
void
*
impl
;
size_t
usize
;
MALLOCATOR_APIS
};
// heap allocator
SMemAllocator
*
tdCreateHeapAllocator
();
void
tdDestroyHeapAllocator
(
SMemAllocator
*
pMemAllocator
);
#define amalloc(allocator, size) ((allocator) ? (*((allocator)->malloc))((allocator)->impl, (size)) : malloc(size))
#define acalloc(allocator, nmemb, size) \
((allocator) ? (*((allocator)->calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size)))
#define arealloc(allocator, ptr, size) \
((allocator) ? (*((allocator)->realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size)))
#define afree(allocator, ptr, size) ((allocator) ? (*((allocator)->free))((allocator)->impl, (ptr), (size)) : free(ptr))
// arena allocator
SMemAllocator
*
tdCreateArenaAllocator
(
size_t
size
);
void
tdDestroyArenaAllocator
(
SMemAllocator
*
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_AMALLOC_H_*/
\ No newline at end of file
#endif
/*_TD_MALLOCATOR_H_*/
\ No newline at end of file
source/dnode/vnode/impl/inc/vnodeInt.h
浏览文件 @
5e9909a1
...
...
@@ -18,7 +18,6 @@
#include "vnode.h"
#include "amalloc.h"
#include "meta.h"
#include "sync.h"
#include "tlog.h"
...
...
source/util/src/arenaAllocator.c
0 → 100644
浏览文件 @
5e9909a1
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
\ No newline at end of file
source/util/src/heapAllocator.c
0 → 100644
浏览文件 @
5e9909a1
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mallocator.h"
typedef
struct
{
char
name
[
64
];
}
SHeapAllocator
;
static
SHeapAllocator
*
haNew
();
static
void
haDestroy
(
SHeapAllocator
*
pha
);
static
void
*
haMalloc
(
SMemAllocator
*
pMemAllocator
,
size_t
size
);
void
*
haCalloc
(
SMemAllocator
*
pMemAllocator
,
size_t
nmemb
,
size_t
size
);
static
void
haFree
(
SMemAllocator
*
pMemAllocator
,
void
*
ptr
);
SMemAllocator
*
tdCreateHeapAllocator
()
{
SMemAllocator
*
pMemAllocator
=
NULL
;
pMemAllocator
=
(
SMemAllocator
*
)
calloc
(
1
,
sizeof
(
*
pMemAllocator
));
if
(
pMemAllocator
==
NULL
)
{
// TODO: handle error
return
NULL
;
}
pMemAllocator
->
impl
=
haNew
();
if
(
pMemAllocator
->
impl
==
NULL
)
{
tdDestroyHeapAllocator
(
pMemAllocator
);
return
NULL
;
}
pMemAllocator
->
usage
=
0
;
pMemAllocator
->
malloc
=
haMalloc
;
pMemAllocator
->
calloc
=
haCalloc
;
pMemAllocator
->
realloc
=
NULL
;
pMemAllocator
->
free
=
haFree
;
pMemAllocator
->
usage
=
NULL
;
return
pMemAllocator
;
}
void
tdDestroyHeapAllocator
(
SMemAllocator
*
pMemAllocator
)
{
if
(
pMemAllocator
)
{
// TODO
}
}
/* ------------------------ STATIC METHODS ------------------------ */
static
SHeapAllocator
*
haNew
()
{
SHeapAllocator
*
pha
=
NULL
;
/* TODO */
return
pha
;
}
static
void
haDestroy
(
SHeapAllocator
*
pha
)
{
// TODO
}
static
void
*
haMalloc
(
SMemAllocator
*
pMemAllocator
,
size_t
size
)
{
void
*
ptr
=
NULL
;
ptr
=
malloc
(
size
);
if
(
ptr
)
{
}
return
ptr
;
}
void
*
haCalloc
(
SMemAllocator
*
pMemAllocator
,
size_t
nmemb
,
size_t
size
)
{
/* TODO */
return
NULL
;
}
static
void
haFree
(
SMemAllocator
*
pMemAllocator
,
void
*
ptr
)
{
/* TODO */
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录