1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-10-08 22:50:06 +02:00
Files
.gitlab-ci
.reuse
LICENSES
docs
fuzzing
gio
girepository
cmph
README-CMPH-IMPORT.txt
bdz.c
bdz.h
bdz_gen_lookup_table.c
bdz_ph.c
bdz_ph.h
bdz_structs.h
bdz_structs_ph.h
bitbool.h
bmz.c
bmz.h
bmz8.c
bmz8.h
bmz8_structs.h
bmz_structs.h
brz.c
brz.h
brz_structs.h
buffer_entry.c
buffer_entry.h
buffer_manage.c
buffer_manage.h
buffer_manager.c
buffer_manager.h
chd.c
chd.h
chd_ph.c
chd_ph.h
chd_structs.h
chd_structs_ph.h
chm.c
chm.h
chm_structs.h
cmph.c
cmph.h
cmph_structs.c
cmph_structs.h
cmph_time.h
cmph_types.h
compressed_rank.c
compressed_rank.h
compressed_seq.c
compressed_seq.h
debug.h
djb2_hash.c
djb2_hash.h
fch.c
fch.h
fch_buckets.c
fch_buckets.h
fch_structs.h
fnv_hash.c
fnv_hash.h
graph.c
graph.h
hash.c
hash.h
hash_state.h
hashtree.c
hashtree.h
hashtree_structs.h
jenkins_hash.c
jenkins_hash.h
main.c
meson.build
miller_rabin.c
miller_rabin.h
sdbm_hash.c
sdbm_hash.h
select.c
select.h
select_lookup_tables.h
vqueue.c
vqueue.h
vstack.c
vstack.h
wingetopt.c
wingetopt.h
tests
tools
gdump.c
gi-dump-types.c
giarginfo.c
giarginfo.h
gibaseinfo-private.h
gibaseinfo.c
gibaseinfo.h
gicallableinfo.c
gicallableinfo.h
gicallbackinfo.c
gicallbackinfo.h
giconstantinfo.c
giconstantinfo.h
gienuminfo.c
gienuminfo.h
gifieldinfo.c
gifieldinfo.h
gifunctioninfo.c
gifunctioninfo.h
giinterfaceinfo.c
giinterfaceinfo.h
ginvoke.c
giobjectinfo.c
giobjectinfo.h
gipropertyinfo.c
gipropertyinfo.h
giregisteredtypeinfo.c
giregisteredtypeinfo.h
girepository-private.h
girepository.c
girepository.h
girffi.c
girffi.h
girmodule-private.h
girmodule.c
girnode-private.h
girnode.c
giroffsets.c
girparser-private.h
girparser.c
girwriter-private.h
girwriter.c
gisignalinfo.c
gisignalinfo.h
gistructinfo.c
gistructinfo.h
gitypeinfo.c
gitypeinfo.h
gitypelib-internal.h
gitypelib.c
gitypelib.h
gitypes.h
giunioninfo.c
giunioninfo.h
giunresolvedinfo.c
giunresolvedinfo.h
givfuncinfo.c
givfuncinfo.h
gthash.c
meson.build
glib
gmodule
gobject
gthread
introspection
m4macros
po
subprojects
tests
tools
.clang-format
.dir-locals.el
.editorconfig
.gitignore
.gitlab-ci.yml
.gitmodules
.lcovrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
INSTALL.md
NEWS
README.md
SECURITY.md
glib.doap
meson.build
meson_options.txt
glib/girepository/cmph/buffer_manage.c

67 lines
2.4 KiB
C
Raw Normal View History

#include "buffer_manage.h"
#include "buffer_entry.h"
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
struct __buffer_manage_t
{
cmph_uint32 memory_avail; // memory available
buffer_entry_t ** buffer_entries; // buffer entries to be managed
cmph_uint32 nentries; // number of entries to be managed
cmph_uint32 *memory_avail_list; // memory available list
int pos_avail_list; // current position in memory available list
};
buffer_manage_t * buffer_manage_new(cmph_uint32 memory_avail, cmph_uint32 nentries)
{
cmph_uint32 memory_avail_entry, i;
buffer_manage_t *buff_manage = (buffer_manage_t *)malloc(sizeof(buffer_manage_t));
assert(buff_manage);
buff_manage->memory_avail = memory_avail;
buff_manage->buffer_entries = (buffer_entry_t **)calloc((size_t)nentries, sizeof(buffer_entry_t *));
buff_manage->memory_avail_list = (cmph_uint32 *)calloc((size_t)nentries, sizeof(cmph_uint32));
buff_manage->pos_avail_list = -1;
buff_manage->nentries = nentries;
memory_avail_entry = buff_manage->memory_avail/buff_manage->nentries + 1;
for(i = 0; i < buff_manage->nentries; i++)
{
buff_manage->buffer_entries[i] = buffer_entry_new(memory_avail_entry);
}
return buff_manage;
}
void buffer_manage_open(buffer_manage_t * buffer_manage, cmph_uint32 index, char * filename)
{
buffer_entry_open(buffer_manage->buffer_entries[index], filename);
}
cmph_uint8 * buffer_manage_read_key(buffer_manage_t * buffer_manage, cmph_uint32 index)
{
cmph_uint8 * key = NULL;
if (buffer_manage->pos_avail_list >= 0 ) // recovering memory
{
cmph_uint32 new_capacity = buffer_entry_get_capacity(buffer_manage->buffer_entries[index]) + buffer_manage->memory_avail_list[(buffer_manage->pos_avail_list)--];
buffer_entry_set_capacity(buffer_manage->buffer_entries[index], new_capacity);
//fprintf(stderr, "recovering memory\n");
}
key = buffer_entry_read_key(buffer_manage->buffer_entries[index]);
if (key == NULL) // storing memory to be recovered
{
buffer_manage->memory_avail_list[++(buffer_manage->pos_avail_list)] = buffer_entry_get_capacity(buffer_manage->buffer_entries[index]);
//fprintf(stderr, "storing memory to be recovered\n");
}
return key;
}
void buffer_manage_destroy(buffer_manage_t * buffer_manage)
{
cmph_uint32 i;
for(i = 0; i < buffer_manage->nentries; i++)
{
buffer_entry_destroy(buffer_manage->buffer_entries[i]);
}
free(buffer_manage->memory_avail_list);
free(buffer_manage->buffer_entries);
free(buffer_manage);
}