Index: source/blender/blenkernel/intern/customdata.c =================================================================== --- source/blender/blenkernel/intern/customdata.c (revision 58357) +++ source/blender/blenkernel/intern/customdata.c (working copy) @@ -49,6 +49,7 @@ #include "BLI_linklist.h" #include "BLI_math.h" #include "BLI_mempool.h" +#include "BLI_cellalloc.h" #include "BLI_utildefines.h" #include "BLF_translation.h" @@ -158,8 +159,8 @@ MDeformVert *dvert = (MDeformVert *)((char *)dest + i * size); if (dvert->totweight) { - MDeformWeight *dw = MEM_callocN(dvert->totweight * sizeof(*dw), - "layerCopy_mdeformvert dw"); + MDeformWeight *dw = BLI_cellalloc_malloc(dvert->totweight * sizeof(*dw), + "layerCopy_mdeformvert dw"); memcpy(dw, dvert->dw, dvert->totweight * sizeof(*dw)); dvert->dw = dw; @@ -177,7 +178,7 @@ MDeformVert *dvert = (MDeformVert *)((char *)data + i * size); if (dvert->dw) { - MEM_freeN(dvert->dw); + BLI_cellalloc_free(dvert->dw); dvert->dw = NULL; dvert->totweight = 0; } @@ -249,8 +250,8 @@ /* if this def_nr is not in the list, add it */ if (!node) { - MDeformWeight *tmp_dw = MEM_callocN(sizeof(*tmp_dw), - "layerInterp_mdeformvert tmp_dw"); + MDeformWeight *tmp_dw = BLI_cellalloc_malloc(sizeof(*tmp_dw), + "layerInterp_mdeformvert tmp_dw"); tmp_dw->def_nr = dw->def_nr; tmp_dw->weight = weight; BLI_linklist_prepend(&dest_dw, tmp_dw); @@ -262,11 +263,11 @@ /* delay writing to the destination incase dest is in sources */ /* now we know how many unique deform weights there are, so realloc */ - if (dvert->dw) MEM_freeN(dvert->dw); + if (dvert->dw) BLI_cellalloc_free(dvert->dw); if (totweight) { - dvert->dw = MEM_callocN(sizeof(*dvert->dw) * totweight, - "layerInterp_mdeformvert dvert->dw"); + dvert->dw = BLI_cellalloc_malloc(sizeof(*dvert->dw) * totweight, + "layerInterp_mdeformvert dvert->dw"); dvert->totweight = totweight; for (i = 0, node = dest_dw; node; node = node->next, ++i) @@ -462,18 +463,18 @@ /* happens when face changed vertex count in edit mode * if it happened, just forgot displacement */ - MEM_freeN(s->disps); + BLI_cellalloc_free(s->disps); s->totdisp = (s->totdisp / corners) * nverts; - s->disps = MEM_callocN(s->totdisp * sizeof(float) * 3, "mdisp swap"); + s->disps = BLI_cellalloc_calloc(s->totdisp * sizeof(float) * 3, "mdisp swap"); return; } - d = MEM_callocN(sizeof(float) * 3 * s->totdisp, "mdisps swap"); + d = BLI_cellalloc_calloc(sizeof(float) * 3 * s->totdisp, "mdisps swap"); for (S = 0; S < corners; S++) memcpy(d + cornersize * S, s->disps + cornersize * ci[S], cornersize * 3 * sizeof(float)); - MEM_freeN(s->disps); + BLI_cellalloc_free(s->disps); s->disps = d; } } @@ -486,8 +487,8 @@ for (i = 0; i < count; ++i) { if (s[i].disps) { - d[i].disps = MEM_dupallocN(s[i].disps); - d[i].hidden = MEM_dupallocN(s[i].hidden); + d[i].disps = BLI_cellalloc_dupalloc(s[i].disps); + d[i].hidden = BLI_cellalloc_dupalloc(s[i].hidden); d[i].totdisp = s[i].totdisp; d[i].level = s[i].level; } @@ -508,9 +509,9 @@ for (i = 0; i < count; ++i) { if (d[i].disps) - MEM_freeN(d[i].disps); + BLI_cellalloc_free(d[i].disps); if (d[i].hidden) - MEM_freeN(d[i].hidden); + BLI_cellalloc_free(d[i].hidden); d[i].disps = NULL; d[i].hidden = NULL; d[i].totdisp = 0; @@ -525,7 +526,7 @@ for (i = 0; i < count; ++i) { if (!d[i].disps) - d[i].disps = MEM_callocN(sizeof(float) * 3 * d[i].totdisp, "mdisps read"); + d[i].disps = BLI_cellalloc_calloc(sizeof(float) * 3 * d[i].totdisp, "mdisps read"); if (!cdf_read_data(cdf, d[i].totdisp * 3 * sizeof(float), d[i].disps)) { printf("failed to read multires displacement %d/%d %d\n", i, count, d[i].totdisp); Index: source/blender/blenkernel/intern/deform.c =================================================================== --- source/blender/blenkernel/intern/deform.c (revision 58357) +++ source/blender/blenkernel/intern/deform.c (working copy) @@ -46,6 +46,7 @@ #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BLI_cellalloc.h" #include "BLF_translation.h" @@ -67,6 +68,7 @@ return defgroup; } + void defgroup_copy_list(ListBase *outbase, ListBase *inbase) { bDeformGroup *defgroup, *defgroupn; @@ -119,10 +121,10 @@ } else { if (dvert_dst->dw) - MEM_freeN(dvert_dst->dw); + BLI_cellalloc_free(dvert_dst->dw); if (dvert_src->totweight) - dvert_dst->dw = MEM_dupallocN(dvert_src->dw); + dvert_dst->dw = BLI_cellalloc_dupalloc(dvert_src->dw); else dvert_dst->dw = NULL; @@ -735,10 +737,10 @@ if (dw_new) return dw_new; - dw_new = MEM_callocN(sizeof(MDeformWeight) * (dvert->totweight + 1), "deformWeight"); + dw_new = BLI_cellalloc_calloc(sizeof(MDeformWeight) * (dvert->totweight + 1), "deformWeight"); if (dvert->dw) { memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight); - MEM_freeN(dvert->dw); + BLI_cellalloc_free(dvert->dw); } dvert->dw = dw_new; dw_new += dvert->totweight; @@ -763,10 +765,10 @@ if (!dvert || defgroup < 0) return; - dw_new = MEM_callocN(sizeof(MDeformWeight) * (dvert->totweight + 1), "defvert_add_to group, new deformWeight"); + dw_new = BLI_cellalloc_calloc(sizeof(MDeformWeight) * (dvert->totweight + 1), "defvert_add_to group, new deformWeight"); if (dvert->dw) { memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight); - MEM_freeN(dvert->dw); + BLI_cellalloc_free(dvert->dw); } dvert->dw = dw_new; dw_new += dvert->totweight; @@ -805,13 +807,13 @@ memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * i); memcpy(dw_new + i, dvert->dw + i + 1, sizeof(MDeformWeight) * (dvert->totweight - i)); #endif - MEM_freeN(dvert->dw); + BLI_cellalloc_free(dvert->dw); } dvert->dw = dw_new; } else { /* If there are no other deform weights left then just remove this one. */ - MEM_freeN(dvert->dw); + BLI_cellalloc_free(dvert->dw); dvert->dw = NULL; } } @@ -820,7 +822,7 @@ void defvert_clear(MDeformVert *dvert) { if (dvert->dw) { - MEM_freeN(dvert->dw); + BLI_cellalloc_free(dvert->dw); dvert->dw = NULL; } @@ -880,7 +882,7 @@ for (i = 0; i < copycount; i++) { if (src[i].dw) { - dst[i].dw = MEM_mallocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight"); + dst[i].dw = BLI_cellalloc_malloc(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight"); memcpy(dst[i].dw, src[i].dw, sizeof(MDeformWeight) * src[i].totweight); } } @@ -899,7 +901,7 @@ /* Free any special data from the verts */ for (i = 0; i < totvert; i++) { - if (dvert[i].dw) MEM_freeN(dvert[i].dw); + if (dvert[i].dw) BLI_cellalloc_free(dvert[i].dw); } } Index: source/blender/blenkernel/intern/mesh.c =================================================================== --- source/blender/blenkernel/intern/mesh.c (revision 58357) +++ source/blender/blenkernel/intern/mesh.c (working copy) @@ -51,6 +51,7 @@ #include "BLI_bitmap.h" #include "BLI_scanfill.h" #include "BLI_array.h" +#include "BLI_cellalloc.h" #include "BKE_animsys.h" #include "BKE_main.h" @@ -2187,9 +2188,9 @@ ld->level = (int)(logf(side - 1.0f) / (float)M_LN2) + 1; if (ld->disps) - MEM_freeN(ld->disps); + BLI_cellalloc_free(ld->disps); - ld->disps = MEM_callocN(sizeof(float) * 3 * side * side, "converted loop mdisps"); + ld->disps = BLI_cellalloc_calloc(sizeof(float) * 3 * side * side, "converted loop mdisps"); if (fd->disps) { memcpy(ld->disps, disps, sizeof(float) * 3 * side * side); } Index: source/blender/blenkernel/intern/multires.c =================================================================== --- source/blender/blenkernel/intern/multires.c (revision 58357) +++ source/blender/blenkernel/intern/multires.c (working copy) @@ -44,6 +44,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_cellalloc.h" #include "BKE_pbvh.h" #include "BKE_ccg.h" @@ -238,7 +239,7 @@ NULL); /* swap in the subdivided data */ - MEM_freeN(md->hidden); + BLI_cellalloc_free(md->hidden); md->hidden = subd; } @@ -268,7 +269,7 @@ BLI_assert(!md->hidden); - md->hidden = BLI_BITMAP_NEW(gridarea, "MDisps.hidden initialize"); + md->hidden = BLI_BITMAP_NEW_CELL(gridarea, "MDisps.hidden initialize"); for (k = 0; k < gridarea; k++) BLI_BITMAP_SET(md->hidden, k); @@ -640,7 +641,7 @@ float (*disps)[3], (*ndisps)[3], (*hdisps)[3]; int totdisp = multires_grid_tot[lvl]; - disps = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps"); + disps = BLI_cellalloc_calloc(sizeof(float) * 3 * totdisp, "multires disps"); ndisps = disps; hdisps = mdisp->disps; @@ -658,7 +659,7 @@ ndisps += nsize * nsize; hdisps += hsize * hsize; - MEM_freeN(mdisp->disps); + BLI_cellalloc_free(mdisp->disps); mdisp->disps = disps; mdisp->totdisp = totdisp; mdisp->level = lvl; @@ -1265,14 +1266,14 @@ BLI_bitmap gh = grid_hidden[i]; if (!gh && md->hidden) { - MEM_freeN(md->hidden); + BLI_cellalloc_free(md->hidden); md->hidden = NULL; } else if (gh) { gh = multires_mdisps_upsample_hidden(gh, lvl, totlvl, md->hidden); if (md->hidden) - MEM_freeN(md->hidden); + BLI_cellalloc_free(md->hidden); md->hidden = gh; } @@ -1550,7 +1551,7 @@ int x, y, S; float (*disps)[3], (*out)[3], u = 0.0f, v = 0.0f; /* Quite gcc barking. */ - disps = MEM_callocN(sizeof(float) * 3 * newtotdisp, "multires disps"); + disps = BLI_cellalloc_calloc(sizeof(float) * 3 * newtotdisp, "multires disps"); out = disps; for (S = 0; S < nvert; S++) { @@ -1567,7 +1568,7 @@ } } - MEM_freeN(mdisp->disps); + BLI_cellalloc_free(mdisp->disps); mdisp->totdisp = newtotdisp; mdisp->level = newlvl; Index: source/blender/blenkernel/intern/particle_system.c =================================================================== --- source/blender/blenkernel/intern/particle_system.c (revision 58357) +++ source/blender/blenkernel/intern/particle_system.c (working copy) @@ -72,6 +72,7 @@ #include "BLI_kdopbvh.h" #include "BLI_threads.h" #include "BLI_linklist.h" +#include "BLI_cellalloc.h" #include "BKE_main.h" #include "BKE_animsys.h" @@ -4013,7 +4014,7 @@ if (dvert) { if (!dvert->totweight) { - dvert->dw = MEM_callocN(sizeof(MDeformWeight), "deformWeight"); + dvert->dw = BLI_cellalloc_calloc(sizeof(MDeformWeight), "deformWeight"); dvert->totweight = 1; } @@ -4034,7 +4035,7 @@ if (dvert) { if (!dvert->totweight) { - dvert->dw = MEM_callocN(sizeof(MDeformWeight), "deformWeight"); + dvert->dw = BLI_cellalloc_calloc(sizeof(MDeformWeight), "deformWeight"); dvert->totweight = 1; } /* roots should be 1.0, the rest can be anything from 0.0 to 1.0 */ Index: source/blender/blenlib/BLI_bitmap.h =================================================================== --- source/blender/blenlib/BLI_bitmap.h (revision 58357) +++ source/blender/blenlib/BLI_bitmap.h (working copy) @@ -51,6 +51,10 @@ ((BLI_bitmap)MEM_callocN(BLI_BITMAP_SIZE(_tot), \ _alloc_string)) +#define BLI_BITMAP_NEW_CELL(_tot, _alloc_string) \ + ((BLI_bitmap)BLI_cellalloc_calloc(BLI_BITMAP_SIZE(_tot), \ + _alloc_string)) + /* get the value of a single bit at '_index' */ #define BLI_BITMAP_GET(_bitmap, _index) \ ((_bitmap)[(_index) >> BLI_BITMAP_POWER] & \ Index: source/blender/blenlib/BLI_cellalloc.h =================================================================== --- source/blender/blenlib/BLI_cellalloc.h (revision 0) +++ source/blender/blenlib/BLI_cellalloc.h (working copy) @@ -0,0 +1,33 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_CELLALLOC_H__ +#define __BLI_CELLALLOC_H__ + +void *BLI_cellalloc_malloc(int size, const char *tag); +void *BLI_cellalloc_calloc(int size, const char *tag); +void BLI_cellalloc_free(void *mem); +void BLI_cellalloc_printleaks(void); +int BLI_cellalloc_get_totblock(void); +void BLI_cellalloc_destroy(void); +void *BLI_cellalloc_dupalloc(void *mem); +void BLI_cellalloc_from_guardedalloc(void **r_ptr); + +#endif /* __BLI_CELLALLOC_H__ */ Property changes on: source/blender/blenlib/BLI_cellalloc.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: source/blender/blenlib/CMakeLists.txt =================================================================== --- source/blender/blenlib/CMakeLists.txt (revision 58357) +++ source/blender/blenlib/CMakeLists.txt (working copy) @@ -25,7 +25,7 @@ # XXX allowing blenkernel and RNA includes in blenlib is a hack, # but needed in a few places atm (bpath.c for instance) -set(INC +set(INC . # ../blenkernel # dont add this back! ../makesdna @@ -50,6 +50,7 @@ intern/BLI_linklist.c intern/BLI_memarena.c intern/BLI_mempool.c + intern/BLI_cellalloc.c intern/DLRB_tree.c intern/boxpack2d.c intern/buffer.c @@ -99,6 +100,7 @@ intern/winstuff.c BLI_args.h + BLI_cellalloc.h BLI_array.h BLI_bitmap.h BLI_blenlib.h Index: source/blender/blenlib/intern/BLI_cellalloc.c =================================================================== --- source/blender/blenlib/intern/BLI_cellalloc.c (revision 0) +++ source/blender/blenlib/intern/BLI_cellalloc.c (working copy) @@ -0,0 +1,247 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Contributor(s): Joseph Eagar + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** + * Simple, fast memory allocator that uses many BLI_mempools for allocation. + * this is meant to be used by lots of relatively small objects. + * + * this is a temporary and imperfect fix for performance issues caused + * by vgroups. it needs to be replaced with something better, preferably + * integrated into guardedalloc. + * + * Basically, it's a quick fix for vgroups and MDisps (both of which + * are major performance hitters). + */ + +/** + * this evil bit of code is necassary for vgroups and multires to run fast + * enough. it is surprisingly tricky allocate MDeformWeights and MDisps in + * a way that doesn't cause severe performance problems. once a better solution + * is found we can get rid of this code, but until then this is necassary + * (though, disabling it if jedmalloc is in use might be feasible). + * + * ideas for replacement: + * ok, mdisps could store a mempool in CustomDataLayer. there might be + * one there already? vgroups, uh. . .not sure what to do with vgroups, + * they do cause a significant performance problem. + * + * it's tempting to split vgroups into lots of little customdata layers, + * but that would waste a LOT of memory. ugh. can we plug in jemalloc + * to guardedalloc, on all platforms? that would work. + * + * I really hate this little library; it really should be replaced before trunk + * reintegration. + * + * - joeedh + */ + +#include + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" + +#include "BLI_blenlib.h" +#include "BLI_linklist.h" + +#include "DNA_listBase.h" +#include "BLI_mempool.h" + +#include "BLI_cellalloc.h" /* own include */ + +#ifdef __GNUC__ +# pragma GCC diagnostic error "-Wsign-conversion" +# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 /* gcc4.6+ only */ +# pragma GCC diagnostic error "-Wsign-compare" +# pragma GCC diagnostic error "-Wconversion" +# endif +#endif + +static BLI_mempool **pools; +static int totpool = 0; +static ListBase active_mem = {NULL, NULL}; +static int celltotblock = 0; + +#define MEMIDCHECK ('a' | ('b' << 4) | ('c' << 8) | ('d' << 12)) + +typedef struct MemHeader { + struct MemHeader *next, *prev; + + const char *tag; + int size; + int idcheck; +} MemHeader; + +//#define USE_GUARDEDALLOC + +void *BLI_cellalloc_malloc(int size, const char *tag) +{ + MemHeader *memh; + int slot = size + (int)sizeof(MemHeader); + +#ifdef USE_GUARDEDALLOC + return MEM_mallocN(size, tag); +#endif + if (!slot) + return NULL; + + /* stupid optimization trick. + * round up to nearest 16 bytes boundary. + * this is to reduce the number of potential + * pools. hopefully it'll help. */ + slot += 16 - (slot & 15); + + if (slot >= totpool) { + void *tmp; + + tmp = calloc(1, sizeof(void *) * (size_t)(slot + 1)); + if (pools) { + memcpy(tmp, pools, (size_t)totpool * sizeof(void *)); + } + + pools = tmp; + totpool = slot + 1; + } + + if (!pools[slot]) { + pools[slot] = BLI_mempool_create(slot, 1, 128, 0); + } + + memh = BLI_mempool_alloc(pools[slot]); + memh->size = size; + memh->idcheck = MEMIDCHECK; + memh->tag = tag; + BLI_addtail(&active_mem, memh); + celltotblock++; + + return memh + 1; +} + +void *BLI_cellalloc_calloc(int size, const char *tag) +{ + void *mem = BLI_cellalloc_malloc(size, tag); + memset(mem, 0, (size_t)size); + return mem; +} + +void BLI_cellalloc_free(void *mem) +{ + MemHeader *memh = mem; + int slot; + +#ifdef USE_GUARDEDALLOC + MEM_freeN(mem); + return; +#endif + if (!memh) + return; + + memh--; + if (memh->idcheck != MEMIDCHECK) { + printf("Error in BLI_cellalloc: attempt to free invalid block.\n"); + return; + } + + slot = memh->size + (int)sizeof(MemHeader); + slot = (slot + 15) & ~15; /* allocate in units of 16 */ + + if (memh->size > 0 && slot < totpool) { + BLI_remlink(&active_mem, memh); + BLI_mempool_free(pools[slot], memh); + celltotblock--; + } + else { + printf("Error in BLI_cellalloc: attempt to free corrupted block.\n"); + } +} + +void *BLI_cellalloc_dupalloc(void *mem) +{ + MemHeader *memh = mem; + void *tmp; + +#ifdef USE_GUARDEDALLOC + MEM_freeN(mem); + return NULL; +#endif + if (!memh) + return NULL; + + memh--; + if (memh->idcheck != MEMIDCHECK) { + printf("Error in BLI_cellalloc: attempt to free invalid block.\n"); + return NULL; + } + + tmp = BLI_cellalloc_malloc(memh->size, memh->tag); + memcpy(tmp, mem, (size_t)memh->size); + + return tmp; +} + +/* utility function to convert a MEM_mallocN to a BLI_cellalloc_malloc */ +void BLI_cellalloc_from_guardedalloc(void **r_ptr) +{ + void *ptr = *r_ptr; + if (ptr) { + const int len = (int)MEM_allocN_len(ptr); + void *ptr_new; + +#if !defined(NDEBUG) && defined(USE_GUARDEDALLOC) + ptr_new = BLI_cellalloc_malloc((size_t)len, MEM_name_ptr(ptr)); +#else + ptr_new = BLI_cellalloc_malloc(len, __func__); +#endif + memcpy(ptr_new, ptr, (size_t)len); + + MEM_freeN(ptr); + r_ptr = ptr_new; + } +} + +void BLI_cellalloc_printleaks(void) +{ + MemHeader *memh; + + if (!active_mem.first) return; + + for (memh = active_mem.first; memh; memh = memh->next) { + printf("%s %d %p\n", memh->tag, memh->size, memh + 1); + } +} + +int BLI_cellalloc_get_totblock(void) +{ + return celltotblock; +} + +void BLI_cellalloc_destroy(void) +{ + int i; + + for (i = 0; i < totpool; i++) { + if (pools[i]) { + BLI_mempool_destroy(pools[i]); + pools[i] = NULL; + } + } +} Index: source/blender/blenloader/intern/readfile.c =================================================================== --- source/blender/blenloader/intern/readfile.c (revision 58357) +++ source/blender/blenloader/intern/readfile.c (working copy) @@ -106,6 +106,7 @@ #include "BLI_endian_switch.h" #include "BLI_blenlib.h" #include "BLI_math.h" +#include "BLI_cellalloc.h" #include "BLI_edgehash.h" #include "BLI_threads.h" @@ -4023,7 +4024,7 @@ MDeformWeight *dw; if (mdverts->dw && (dw = newdataadr(fd, mdverts->dw))) { const ssize_t dw_len = mdverts->totweight * sizeof(MDeformWeight); - void *dw_tmp = MEM_mallocN(dw_len, "direct_link_dverts"); + void *dw_tmp = BLI_cellalloc_malloc(dw_len, "direct_link_dverts"); memcpy(dw_tmp, dw, dw_len); mdverts->dw = dw_tmp; MEM_freeN(dw); @@ -4053,6 +4054,10 @@ mdisps[i].level = (int)(logf(gridsize - 1.0f) / (float)M_LN2) + 1; } + /*put .disps into cellalloc system*/ + BLI_cellalloc_from_guardedalloc((void **)&(mdisps[i].disps)); + BLI_cellalloc_from_guardedalloc((void **)&(mdisps[i].hidden)); + if ((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && (mdisps[i].disps)) { /* DNA_struct_switch_endian doesn't do endian swap for (*disps)[] */ /* this does swap for data written at write_mdisps() - readfile.c */ Index: source/blender/bmesh/intern/bmesh_interp.c =================================================================== --- source/blender/bmesh/intern/bmesh_interp.c (revision 58357) +++ source/blender/bmesh/intern/bmesh_interp.c (working copy) @@ -38,6 +38,7 @@ #include "BLI_array.h" #include "BLI_math.h" +#include "BLI_cellalloc.h" #include "BKE_customdata.h" #include "BKE_multires.h" @@ -454,7 +455,7 @@ md_dst->totdisp = md_src->totdisp; md_dst->level = md_src->level; if (md_dst->totdisp) { - md_dst->disps = MEM_callocN(sizeof(float) * 3 * md_dst->totdisp, __func__); + md_dst->disps = BLI_cellalloc_calloc(sizeof(float) * 3 * md_dst->totdisp, __func__); } else { return; Index: source/blender/bmesh/intern/bmesh_mesh.c =================================================================== --- source/blender/bmesh/intern/bmesh_mesh.c (revision 58357) +++ source/blender/bmesh/intern/bmesh_mesh.c (working copy) @@ -34,6 +34,7 @@ #include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_cellalloc.h" #include "BKE_cdderivedmesh.h" #include "BKE_editmesh.h" @@ -400,9 +401,9 @@ } else if (mdisps->disps) { if (lmd->disps) - MEM_freeN(lmd->disps); + BLI_cellalloc_free(lmd->disps); - lmd->disps = MEM_dupallocN(mdisps->disps); + lmd->disps = BLI_cellalloc_dupalloc(mdisps->disps); lmd->totdisp = mdisps->totdisp; lmd->level = mdisps->level; } Index: source/blender/editors/object/object_vgroup.c =================================================================== --- source/blender/editors/object/object_vgroup.c (revision 58357) +++ source/blender/editors/object/object_vgroup.c (working copy) @@ -50,6 +50,7 @@ #include "BLI_array.h" #include "BLI_math.h" #include "BLI_blenlib.h" +#include "BLI_cellalloc.h" #include "BLI_utildefines.h" #include "BLF_translation.h" @@ -409,12 +410,12 @@ for (i = 0; i < dvert_tot; i++, dvf++, dv++) { if ((*dv)->dw) - MEM_freeN((*dv)->dw); + BLI_cellalloc_free((*dv)->dw); *(*dv) = *(*dvf); if ((*dv)->dw) - (*dv)->dw = MEM_dupallocN((*dv)->dw); + (*dv)->dw = BLI_cellalloc_dupalloc((*dv)->dw); } MEM_freeN(dvert_array); @@ -2190,7 +2191,7 @@ if (num_to_drop > 0) { /* re-pack dw array so that non-bone weights are first, bone-weighted verts at end * sort the tail, then copy only the truncated array back to dv->dw */ - dw_temp = MEM_mallocN(sizeof(MDeformWeight) * dv->totweight, __func__); + dw_temp = BLI_cellalloc_malloc(sizeof(MDeformWeight) * dv->totweight, __func__); bone_count = 0; non_bone_count = 0; for (j = 0; j < dv->totweight; j++) { if (LIKELY(dv->dw[j].def_nr < vgroup_tot) && @@ -2210,12 +2211,12 @@ qsort(&dw_temp[non_bone_count], bone_count, sizeof(MDeformWeight), inv_cmp_mdef_vert_weights); dv->totweight -= num_to_drop; /* Do we want to clean/normalize here? */ - MEM_freeN(dv->dw); + BLI_cellalloc_free(dv->dw); dv->dw = MEM_reallocN(dw_temp, sizeof(MDeformWeight) * dv->totweight); remove_tot += num_to_drop; } else { - MEM_freeN(dw_temp); + BLI_cellalloc_free(dw_temp); } } Index: source/blender/editors/sculpt_paint/paint_vertex.c =================================================================== --- source/blender/editors/sculpt_paint/paint_vertex.c (revision 58357) +++ source/blender/editors/sculpt_paint/paint_vertex.c (working copy) @@ -34,6 +34,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_memarena.h" +#include "BLI_cellalloc.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -1717,7 +1718,7 @@ MDeformVert *dv = &me->dvert[index]; MDeformVert dv_test = {NULL}; - dv_test.dw = MEM_dupallocN(dv->dw); + dv_test.dw = BLI_cellalloc_dupalloc(dv->dw); dv_test.flag = dv->flag; dv_test.totweight = dv->totweight; /* do not multi-paint if a locked group is selected or the active group is locked @@ -1748,19 +1749,19 @@ if (tdw->weight != oldw) { if (neww > oldw) { if (tdw->weight <= oldw) { - MEM_freeN(dv_test.dw); + BLI_cellalloc_free(dv_test.dw); return TRUE; } } else { if (tdw->weight >= oldw) { - MEM_freeN(dv_test.dw); + BLI_cellalloc_free(dv_test.dw); return TRUE; } } } } - MEM_freeN(dv_test.dw); + BLI_cellalloc_free(dv_test.dw); return FALSE; } @@ -1947,7 +1948,7 @@ /* setup multi-paint */ observedChange = neww - oldw; if (do_multipaint_totsel && observedChange) { - dv_copy.dw = MEM_dupallocN(dv->dw); + dv_copy.dw = BLI_cellalloc_dupalloc(dv->dw); dv_copy.flag = dv->flag; dv_copy.totweight = dv->totweight; tdw = dw; @@ -2001,7 +2002,7 @@ oldChange = 0; } if (dv_copy.dw) { - MEM_freeN(dv_copy.dw); + BLI_cellalloc_free(dv_copy.dw); } #if 0 /* dv may have been altered greatly */ Index: source/blender/windowmanager/intern/wm_init_exit.c =================================================================== --- source/blender/windowmanager/intern/wm_init_exit.c (revision 58357) +++ source/blender/windowmanager/intern/wm_init_exit.c (working copy) @@ -52,6 +52,7 @@ #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BLI_cellalloc.h" #include "BKE_blender.h" #include "BKE_context.h" @@ -511,9 +512,14 @@ GHOST_DisposeSystemPaths(); if (MEM_get_memory_blocks_in_use() != 0) { - printf("Error: Not freed memory blocks: %d\n", MEM_get_memory_blocks_in_use()); + printf("Error: Not freed memory blocks: %d\n", + MEM_get_memory_blocks_in_use() + BLI_cellalloc_get_totblock()); MEM_printmemlist(); + BLI_cellalloc_printleaks(); } + + BLI_cellalloc_destroy(); + wm_autosave_delete(); printf("\nBlender quit\n");