当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 1 Fork 1

白一梓 / shmdb
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

#shmdb 基于共享内存的内存数据库

1.能做什么

shmdb旨在解决多进程的内存共享问题。在linux或者windows下,操作系统提供共享内存的功能,可以通过调用系统函数申请一段内存区域,shmdb就是利用了操作系统的这个特性,构架一个key-value类型的数据库。使用时,通过函数shmdb_put来设置一对key-value,同样通过函数shmdb_get来获取一对key-value。

2.不能做什么

shmdb没有提供网络访问功能,仅仅只能嵌入到应用程序中来运行。所以不适合做网络数据库使用。

3.API

3.1 shmdb_initParent 初始化父进程

int shmdb_initParent(STHashShareHandle *handle,unsigned int size)

参数

  • [in|out] STHashShareHandle *handle 函数内部会给handle的shmid成员变量赋值
  • unsigned int size 指定base区域的长度
  • [in] STShmdbOption *option 日志选项,可以为NULL

返回值

  • int 操作结果

3.2 shmdb_initChild 初始化子进程

int shmdb_initChild(STHashShareHandle *handle)	

参数

  • [in] STHashShareHandle *handle 函数内部会根据handle的shmid值来将共享内存挂载到自己的内存区域

返回值

  • int 操作结果

3.3 shmdb_put 写入值

int shmdb_put(STHashShareHandle *handle,const char*key,unsigned short keyLen,
const char *value,unsigned short valueLen)

参数

  • [in] STHashShareHandle *handle 函数内部读取handle内shmid值来操作共享内存
  • [in] const char *key
  • unsigned short keyLen
  • [in] const char *value
  • unsigned short valueLen

返回值

  • int 操作结果

3.4 shmdb_get 获取值

shmdb_get(STHashShareHandle *handle,const char*key,unsigned short keyLen,
char **value,unsigned short *valueLen)

参数

  • [in] STHashShareHandle *handle 函数内部读取handle内shmid值来操作共享内存
  • [in] const char *key
  • unsigned short keyLen
  • [out] char **value 函数在内部申请value的内存空间,调用完成后要手动调用free释放。如果valueLen的值为NULL,则函数内部不会对value申请内存。
  • unsigned short *valueLen

返回值

  • int 操作结果

3.5 shmdb_delete 删除值

int shmdb_delete(STHashShareHandle *handle,const char *key,unsigned short keyLen,
char **value,unsigned short *valueLen) 

参数

  • [in] STHashShareHandle *handle 函数内部读取handle内shmid值来操作共享内存
  • [in] const char *key
  • unsigned short keyLen
  • [out] char **value 函数在内部申请得到的内容的内存空间,调用完成后要手动调用free释放。如果valueLen的值为NULL,则函数内部不会对value申请内存。
  • unsigned short *valueLen

返回值

  • int 操作结果

3.6 shmdb_destroy 销毁

在程序正常退出时,应该手动调用该函数将共享内存从操作系统中移除。

int shmdb_destroy(STHashShareHandle *handle)

参数

  • [in] STHashShareHandle *handle 函数内部读取handle内shmid值来操作共享内存

返回值

  • int 操作结果

贡献者

yunnysunny (maintainer)

License: Apache License, Version 2.0

Copyright 2014- yunnysunny@gmail.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

迁移到了github https://github.com/yunnysunny/shmdb 展开 收起
C
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/yunnysunny/shmdb.git
git@gitee.com:yunnysunny/shmdb.git
yunnysunny
shmdb
shmdb
master

搜索帮助