summaryrefslogtreecommitdiff
path: root/src/common/malloc.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-12-17 23:02:13 -0200
committershennetsind <ind@henn.et>2013-12-17 23:02:13 -0200
commit38f6b2c68c59d3ed2e3fc6d4d75907939c4fdf61 (patch)
tree45b4bf49bca0ffb5fabe7405f445caa22cc215f8 /src/common/malloc.c
parent46a990697bdacaf3955c54e0b9d8503f3b704728 (diff)
downloadhercules-38f6b2c68c59d3ed2e3fc6d4d75907939c4fdf61.tar.gz
hercules-38f6b2c68c59d3ed2e3fc6d4d75907939c4fdf61.tar.bz2
hercules-38f6b2c68c59d3ed2e3fc6d4d75907939c4fdf61.tar.xz
hercules-38f6b2c68c59d3ed2e3fc6d4d75907939c4fdf61.zip
Speed up of several procedures that rely on ERS, _mreallocz ('z'ero)
Made Possible Thanks to the Woonderful Haruna! <3 Commit also fixes an inconsistency in the ERS, where it'd start with clear memory but would use garbage upon resizing, also implements a new ERS option that clears entries as soon as pass by ers_free, so that they'll be all shinny for when ers_alloc reuses them. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common/malloc.c')
-rw-r--r--src/common/malloc.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 23e28a65f..875b87a15 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -369,6 +369,37 @@ void* _mrealloc(void *memblock, size_t size, const char *file, int line, const c
}
}
+/* a _mrealloc clone with the difference it 'z'eroes the newly created memory */
+void* _mreallocz(void *memblock, size_t size, const char *file, int line, const char *func ) {
+ size_t old_size;
+ void *p = NULL;
+
+ if(memblock == NULL) {
+ p = iMalloc->malloc(size,file,line,func);
+ memset(p,0,size);
+ return p;
+ }
+
+ old_size = ((struct unit_head *)((char *)memblock - sizeof(struct unit_head) + sizeof(long)))->size;
+ if( old_size == 0 ) {
+ old_size = ((struct unit_head_large *)((char *)memblock - sizeof(struct unit_head_large) + sizeof(long)))->size;
+ }
+ if(old_size > size) {
+ // Size reduction - return> as it is (negligence)
+ return memblock;
+ } else {
+ // Size Large
+ p = iMalloc->malloc(size,file,line,func);
+ if(p != NULL) {
+ memcpy(p,memblock,old_size);
+ memset(p+old_size,0,size-old_size);
+ }
+ iMalloc->free(memblock,file,line,func);
+ return p;
+ }
+}
+
+
char* _mstrdup(const char *p, const char *file, int line, const char *func )
{
if(p == NULL) {
@@ -822,12 +853,14 @@ void malloc_defaults(void) {
iMalloc->malloc = _mmalloc;
iMalloc->calloc = _mcalloc;
iMalloc->realloc = _mrealloc;
+ iMalloc->reallocz= _mreallocz;
iMalloc->astrdup = _mstrdup;
iMalloc->free = _mfree;
#else
iMalloc->malloc = aMalloc_;
iMalloc->calloc = aCalloc_;
iMalloc->realloc = aRealloc_;
+ iMalloc->reallocz= aRealloc_;/* not using memory manager huhum o.o perhaps we could still do something about */
iMalloc->astrdup = aStrdup_;
iMalloc->free = aFree_;
#endif