diff options
author | shennetsind <ind@henn.et> | 2013-06-13 08:21:57 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-06-13 08:21:57 -0300 |
commit | 5e90c5fd3ff133a8f8ba9787d8f83c48840a7a96 (patch) | |
tree | 9423ca650d743c936ae0e4f0bce8aae6ff23e696 /src/common | |
parent | 4b713e7e3eac34339285125d194ae4ff4627fc2a (diff) | |
download | hercules-5e90c5fd3ff133a8f8ba9787d8f83c48840a7a96.tar.gz hercules-5e90c5fd3ff133a8f8ba9787d8f83c48840a7a96.tar.bz2 hercules-5e90c5fd3ff133a8f8ba9787d8f83c48840a7a96.tar.xz hercules-5e90c5fd3ff133a8f8ba9787d8f83c48840a7a96.zip |
Memory Slasher [2] !!" - 17MB Down!
Hercules is now even slimmer.
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/db.c | 1 | ||||
-rw-r--r-- | src/common/ers.c | 21 | ||||
-rw-r--r-- | src/common/ers.h | 6 |
3 files changed, 25 insertions, 3 deletions
diff --git a/src/common/db.c b/src/common/db.c index 561371787..99c758a8d 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -2611,6 +2611,7 @@ void* db_data2ptr(DBData *data) void db_init(void) { db_iterator_ers = ers_new(sizeof(struct DBIterator_impl),"db.c::db_iterator_ers",ERS_OPT_NONE); db_alloc_ers = ers_new(sizeof(struct DBMap_impl),"db.c::db_alloc_ers",ERS_OPT_NONE); + ers_chunk_size(db_alloc_ers, 50); DB_COUNTSTAT(db_init); } diff --git a/src/common/ers.c b/src/common/ers.c index 69b7609d6..27d9222ff 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -84,6 +84,9 @@ typedef struct ers_cache // Objects in-use count unsigned int UsedObjs; + // Default = ERS_BLOCK_ENTRIES, can be adjusted for performance for individual cache sizes. + unsigned int ChunkSize; + // Linked list struct ers_cache *Next, *Prev; } ers_cache_t; @@ -136,6 +139,7 @@ static ers_cache_t *ers_find_cache(unsigned int size) cache->Used = 0; cache->UsedObjs = 0; cache->Max = 0; + cache->ChunkSize = ERS_BLOCK_ENTRIES; if (CacheList == NULL) { @@ -200,10 +204,10 @@ static void *ers_obj_alloc_entry(ERS self) RECREATE(instance->Cache->Blocks, unsigned char *, instance->Cache->Max); } - CREATE(instance->Cache->Blocks[instance->Cache->Used], unsigned char, instance->Cache->ObjectSize * ERS_BLOCK_ENTRIES); + CREATE(instance->Cache->Blocks[instance->Cache->Used], unsigned char, instance->Cache->ObjectSize * instance->Cache->ChunkSize); instance->Cache->Used++; - instance->Cache->Free = ERS_BLOCK_ENTRIES -1; + instance->Cache->Free = instance->Cache->ChunkSize -1; ret = &instance->Cache->Blocks[instance->Cache->Used - 1][instance->Cache->Free * instance->Cache->ObjectSize + sizeof(struct ers_list)]; } @@ -286,6 +290,18 @@ static void ers_obj_destroy(ERS self) aFree(instance); } +void ers_cache_size(ERS self, unsigned int new_size) { + struct ers_instance_t *instance = (struct ers_instance_t *)self; + + if (instance == NULL) { + ShowError("ers_cache_size: NULL object, skipping...\n"); + return; + } + + instance->Cache->ChunkSize = new_size; +} + + ERS ers_new(uint32 size, char *name, enum ERSOptions options) { struct ers_instance_t *instance; @@ -299,6 +315,7 @@ ERS ers_new(uint32 size, char *name, enum ERSOptions options) instance->VTable.free = ers_obj_free_entry; instance->VTable.entry_size = ers_obj_entry_size; instance->VTable.destroy = ers_obj_destroy; + instance->VTable.chunk_size = ers_cache_size; instance->Name = ( options & ERS_OPT_FREE_NAME ) ? aStrdup(name) : name; instance->Options = options; diff --git a/src/common/ers.h b/src/common/ers.h index 4871d8d50..51701d778 100644 --- a/src/common/ers.h +++ b/src/common/ers.h @@ -119,6 +119,8 @@ typedef struct eri { */ void (*destroy)(struct eri *self); + /* */ + void (*chunk_size) (struct eri *self, unsigned int new_size); } *ERS; #ifdef DISABLE_ERS @@ -127,6 +129,7 @@ typedef struct eri { # define ers_free(obj,entry) aFree(entry) # define ers_entry_size(obj) (size_t)0 # define ers_destroy(obj) +# define ers_chunk_size(obj,size) // Disable the public functions # define ers_new(size,name,options) NULL # define ers_report() @@ -138,6 +141,7 @@ typedef struct eri { # define ers_free(obj,entry) (obj)->free((obj),(entry)) # define ers_entry_size(obj) (obj)->entry_size(obj) # define ers_destroy(obj) (obj)->destroy(obj) +# define ers_chunk_size(obj,size) (obj)->chunk_size(obj,size) /** * Get a new instance of the manager that handles the specified entry size. @@ -154,7 +158,7 @@ ERS ers_new(uint32 size, char *name, enum ERSOptions options); /** * Print a report about the current state of the Entry Reusage System. * Shows information about the global system and each entry manager. - * The number of entries are checked and a warning is shown if extra reusable + * The number of entries are checked and a warning is shown if extra reusable * entries are found. * The extra entries are included in the count of reusable entries. */ |