1
0
mirror of https://github.com/fumiama/simple-dict.git synced 2026-06-05 02:00:25 +08:00

reduce mem use

This commit is contained in:
fumiama
2021-12-17 14:48:29 +08:00
parent 567c4d5b92
commit 00c7936e1f
3 changed files with 6 additions and 1 deletions

4
dict.c
View File

@@ -90,6 +90,10 @@ FILE* get_dict_fp(uint32_t index) {
else return NULL;
}
FILE* get_unique_dict_fp() {
return fp5;
}
void close_dict(uint8_t lock_type, uint32_t index) {
puts("Close dict");
lock &= ~lock_type;

1
dict.h
View File

@@ -21,6 +21,7 @@ void close_dict(uint8_t lock_type, uint32_t index);
int fill_md5();
FILE* get_dict_fp(uint32_t index);
off_t get_dict_size();
FILE* get_unique_dict_fp();
int is_md5_equal(uint8_t* digest);
FILE *open_dict(uint8_t lock_type, uint32_t index);

View File

@@ -550,6 +550,7 @@ static void accept_client() {
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 1);
init_crypto();
init_dict_pool(get_unique_dict_fp());
if(pid < 0) puts("Error when forking a subprocess.");
else while(1) {
puts("Ready for accept, waitting...");
@@ -612,7 +613,6 @@ int main(int argc, char *argv[]) {
fp = fopen(argv[as_daemon?4:3], "rb+");
if(!fp) fp = fopen(argv[as_daemon?4:3], "wb+");
if(fp) {
init_dict_pool(fp);
fclose(fp);
if(init_dict(argv[as_daemon?4:3])) {
fp = NULL;