Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
17578d24
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
17578d24
编写于
11月 09, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
867b9072
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
187 addition
and
15 deletion
+187
-15
include/util/mallocator.h
include/util/mallocator.h
+7
-1
source/util/src/arenaAllocator.c
source/util/src/arenaAllocator.c
+0
-14
source/util/src/mallocator.c
source/util/src/mallocator.c
+180
-0
未找到文件。
include/util/mallocator.h
浏览文件 @
17578d24
...
...
@@ -27,7 +27,7 @@ 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 *(*realloc)(SMemAllocator *,
void *ptr, size_t size);
\
void (*free)(SMemAllocator *, void *ptr); \
size_t (*usage)(SMemAllocator *);
...
...
@@ -50,6 +50,12 @@ void tdDestroyHeapAllocator(SMemAllocator *pMemAllocator);
SMemAllocator
*
tdCreateArenaAllocator
(
size_t
size
);
void
tdDestroyArenaAllocator
(
SMemAllocator
*
);
#define mMalloc(pMemAllocator, size) (*(pMemAllocator->malloc))(pMemAllocator, size)
#define mCalloc(pMemAllocator, nmemb, size) (*(pMemAllocator->calloc))(pMemAllocator, nmemb, size)
#define mRealloc(pMemAllocator, ptr, size) (*(pMemAllocator->realloc))(pMemAllocator, ptr, size)
#define mFree(pMemAllocator, ptr) (*(pMemAllocator->free))(pMemAllocator, ptr)
#define mUsage(pMemAllocator) (*(pMemAllocator->usage))(pMemAllocator)
#ifdef __cplusplus
}
#endif
...
...
source/util/src/arenaAllocator.c
已删除
100644 → 0
浏览文件 @
867b9072
/*
* 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/
heapA
llocator.c
→
source/util/src/
ma
llocator.c
浏览文件 @
17578d24
...
...
@@ -15,6 +15,100 @@
#include "mallocator.h"
/* ------------------------ HEAP ALLOCATOR ------------------------ */
typedef
struct
{
size_t
tusage
;
}
SHeapAllocator
;
static
void
*
haMalloc
(
SMemAllocator
*
pma
,
size_t
size
);
static
void
*
haCalloc
(
SMemAllocator
*
pma
,
size_t
nmemb
,
size_t
size
);
static
void
*
haRealloc
(
SMemAllocator
*
pma
,
void
*
ptr
,
size_t
size
);
static
void
haFree
(
SMemAllocator
*
pma
,
void
*
ptr
);
static
size_t
haUsage
(
SMemAllocator
*
pma
);
SMemAllocator
*
tdCreateHeapAllocator
()
{
SMemAllocator
*
pma
=
NULL
;
pma
=
calloc
(
1
,
sizeof
(
SMemAllocator
)
+
sizeof
(
SHeapAllocator
));
if
(
pma
)
{
pma
->
impl
=
POINTER_SHIFT
(
pma
,
sizeof
(
SMemAllocator
));
pma
->
malloc
=
haMalloc
;
pma
->
calloc
=
haCalloc
;
pma
->
realloc
=
haRealloc
;
pma
->
free
=
haFree
;
pma
->
usage
=
haUsage
;
}
return
pma
;
}
void
tdDestroyHeapAllocator
(
SMemAllocator
*
pMemAllocator
)
{
// TODO
}
static
void
*
haMalloc
(
SMemAllocator
*
pma
,
size_t
size
)
{
void
*
ptr
;
size_t
tsize
=
size
+
sizeof
(
size_t
);
SHeapAllocator
*
pha
=
(
SHeapAllocator
*
)(
pma
->
impl
);
ptr
=
malloc
(
tsize
);
if
(
ptr
)
{
*
(
size_t
*
)
ptr
=
size
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
size_t
));
atomic_fetch_add_64
(
&
(
pha
->
tusage
),
tsize
);
}
return
ptr
;
}
static
void
*
haCalloc
(
SMemAllocator
*
pma
,
size_t
nmemb
,
size_t
size
)
{
void
*
ptr
;
size_t
tsize
=
nmemb
*
size
;
ptr
=
haMalloc
(
pma
,
tsize
);
if
(
ptr
)
{
memset
(
ptr
,
0
,
tsize
);
}
return
ptr
;
}
static
void
*
haRealloc
(
SMemAllocator
*
pma
,
void
*
ptr
,
size_t
size
)
{
size_t
psize
;
size_t
tsize
=
size
+
sizeof
(
size_t
);
if
(
ptr
==
NULL
)
{
psize
=
0
;
}
else
{
psize
=
*
(
size_t
*
)
POINTER_SHIFT
(
ptr
,
-
sizeof
(
size_t
));
}
if
(
psize
<
size
)
{
// TODO
}
else
{
return
ptr
;
}
}
static
void
haFree
(
SMemAllocator
*
pma
,
void
*
ptr
)
{
/* TODO */
SHeapAllocator
*
pha
=
(
SHeapAllocator
*
)(
pma
->
impl
);
if
(
ptr
)
{
size_t
tsize
=
*
(
size_t
*
)
POINTER_SHIFT
(
ptr
,
-
sizeof
(
size_t
))
+
sizeof
(
size_t
);
atomic_fetch_sub_64
(
&
(
pha
->
tusage
),
tsize
);
free
(
POINTER_SHIFT
(
ptr
,
-
sizeof
(
size_t
)));
}
}
static
size_t
haUsage
(
SMemAllocator
*
pma
)
{
return
((
SHeapAllocator
*
)(
pma
->
impl
))
->
tusage
;
}
/* ------------------------ ARENA ALLOCATOR ------------------------ */
typedef
struct
{
size_t
usage
;
}
SArenaAllocator
;
#if 0
SMemAllocator *pDefaultMA;
typedef struct {
char name[64];
} SHeapAllocator;
...
...
@@ -82,4 +176,5 @@ void *haCalloc(SMemAllocator *pMemAllocator, size_t nmemb, size_t size) {
}
static void haFree(SMemAllocator *pMemAllocator, void *ptr) { /* TODO */
}
\ No newline at end of file
}
#endif
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录