[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26709] trunk/blender/intern/guardedalloc: Guardedalloc: added MEM_reallocN function to do simple alloc/memcpy/free,
Brecht Van Lommel
brecht at blender.org
Mon Feb 8 15:59:59 CET 2010
Revision: 26709
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26709
Author: blendix
Date: 2010-02-08 15:59:59 +0100 (Mon, 08 Feb 2010)
Log Message:
-----------
Guardedalloc: added MEM_reallocN function to do simple alloc/memcpy/free,
not as optimized as a system realloc but I've had to do this often enough
manually to justify a utility function.
Modified Paths:
--------------
trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
trunk/blender/intern/guardedalloc/intern/mallocn.c
Modified: trunk/blender/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- trunk/blender/intern/guardedalloc/MEM_guardedalloc.h 2010-02-08 14:43:44 UTC (rev 26708)
+++ trunk/blender/intern/guardedalloc/MEM_guardedalloc.h 2010-02-08 14:59:59 UTC (rev 26709)
@@ -85,6 +85,13 @@
void *MEM_dupallocN(void *vmemh);
/**
+ * Reallocates a block of memory, and returns pointer to the newly
+ * allocated block, the old one is freed. this is not as optimized
+ * as a system realloc but just makes a new allocation and copies
+ * over from existing memory. */
+ void *MEM_reallocN(void *vmemh, unsigned int len);
+
+ /**
* Allocate a block of memory of size len, with tag name str. The
* memory is cleared. The name must be static, because only a
* pointer to it is stored ! */
Modified: trunk/blender/intern/guardedalloc/intern/mallocn.c
===================================================================
--- trunk/blender/intern/guardedalloc/intern/mallocn.c 2010-02-08 14:43:44 UTC (rev 26708)
+++ trunk/blender/intern/guardedalloc/intern/mallocn.c 2010-02-08 14:59:59 UTC (rev 26709)
@@ -225,6 +225,28 @@
return newp;
}
+void *MEM_reallocN(void *vmemh, unsigned int len)
+{
+ void *newp= NULL;
+
+ if (vmemh) {
+ MemHead *memh= vmemh;
+ memh--;
+
+ newp= MEM_mallocN(len, memh->name);
+ if(newp) {
+ if(len < memh->len)
+ memcpy(newp, vmemh, len);
+ else
+ memcpy(newp, vmemh, memh->len);
+ }
+
+ MEM_freeN(vmemh);
+ }
+
+ return newp;
+}
+
static void make_memhead_header(MemHead *memh, unsigned int len, const char *str)
{
MemTail *memt;
More information about the Bf-blender-cvs
mailing list