remove cellalloc, from my tests jemalloc beats cellalloc, so we better just use a better malloc replacement.
See Details: http://wiki.blender.org/index.php/User:Ideasman42/BMeshBranchReview#Update_43694
This commit is contained in:
@@ -49,7 +49,6 @@
|
||||
#include "BLI_linklist.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_mempool.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_customdata.h"
|
||||
@@ -139,7 +138,7 @@ static void layerCopy_mdeformvert(const void *source, void *dest,
|
||||
MDeformVert *dvert = (MDeformVert *)((char *)dest + i * size);
|
||||
|
||||
if(dvert->totweight) {
|
||||
MDeformWeight *dw = BLI_cellalloc_calloc(dvert->totweight * sizeof(*dw),
|
||||
MDeformWeight *dw = MEM_callocN(dvert->totweight * sizeof(*dw),
|
||||
"layerCopy_mdeformvert dw");
|
||||
|
||||
memcpy(dw, dvert->dw, dvert->totweight * sizeof(*dw));
|
||||
@@ -158,7 +157,7 @@ static void layerFree_mdeformvert(void *data, int count, int size)
|
||||
MDeformVert *dvert = (MDeformVert *)((char *)data + i * size);
|
||||
|
||||
if(dvert->dw) {
|
||||
BLI_cellalloc_free(dvert->dw);
|
||||
MEM_freeN(dvert->dw);
|
||||
dvert->dw = NULL;
|
||||
dvert->totweight = 0;
|
||||
}
|
||||
@@ -167,7 +166,7 @@ static void layerFree_mdeformvert(void *data, int count, int size)
|
||||
|
||||
static void linklist_free_simple(void *link)
|
||||
{
|
||||
BLI_cellalloc_free(link);
|
||||
MEM_freeN(link);
|
||||
}
|
||||
|
||||
static void layerInterp_mdeformvert(void **sources, float *weights,
|
||||
@@ -200,7 +199,7 @@ static void layerInterp_mdeformvert(void **sources, float *weights,
|
||||
|
||||
/* if this def_nr is not in the list, add it */
|
||||
if(!node) {
|
||||
MDeformWeight *tmp_dw = BLI_cellalloc_calloc(sizeof(*tmp_dw),
|
||||
MDeformWeight *tmp_dw = MEM_callocN(sizeof(*tmp_dw),
|
||||
"layerInterp_mdeformvert tmp_dw");
|
||||
tmp_dw->def_nr = dw->def_nr;
|
||||
tmp_dw->weight = dw->weight * interp_weight;
|
||||
@@ -211,10 +210,10 @@ static void layerInterp_mdeformvert(void **sources, float *weights,
|
||||
}
|
||||
|
||||
/* now we know how many unique deform weights there are, so realloc */
|
||||
if(dvert->dw) BLI_cellalloc_free(dvert->dw);
|
||||
if(dvert->dw) MEM_freeN(dvert->dw);
|
||||
|
||||
if(totweight) {
|
||||
dvert->dw = BLI_cellalloc_calloc(sizeof(*dvert->dw) * totweight,
|
||||
dvert->dw = MEM_callocN(sizeof(*dvert->dw) * totweight,
|
||||
"layerInterp_mdeformvert dvert->dw");
|
||||
dvert->totweight = totweight;
|
||||
|
||||
@@ -430,18 +429,18 @@ static void layerSwap_mdisps(void *data, const int *ci)
|
||||
/* happens when face changed vertex count in edit mode
|
||||
if it happened, just forgot displacement */
|
||||
|
||||
BLI_cellalloc_free(s->disps);
|
||||
MEM_freeN(s->disps);
|
||||
s->totdisp= (s->totdisp/corners)*nverts;
|
||||
s->disps= BLI_cellalloc_calloc(s->totdisp*sizeof(float)*3, "mdisp swap");
|
||||
s->disps= MEM_callocN(s->totdisp*sizeof(float)*3, "mdisp swap");
|
||||
return;
|
||||
}
|
||||
|
||||
d= BLI_cellalloc_calloc(sizeof(float) * 3 * s->totdisp, "mdisps swap");
|
||||
d= MEM_callocN(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));
|
||||
|
||||
BLI_cellalloc_free(s->disps);
|
||||
MEM_freeN(s->disps);
|
||||
s->disps= d;
|
||||
}
|
||||
}
|
||||
@@ -458,7 +457,7 @@ static void layerInterp_mdisps(void **sources, float *UNUSED(weights),
|
||||
}
|
||||
|
||||
if (!d->disps && d->totdisp)
|
||||
d->disps = BLI_cellalloc_calloc(sizeof(float)*3*d->totdisp, "blank mdisps in layerInterp_mdisps");
|
||||
d->disps = MEM_callocN(sizeof(float)*3*d->totdisp, "blank mdisps in layerInterp_mdisps");
|
||||
}
|
||||
|
||||
#else // BMESH_TODO
|
||||
@@ -585,7 +584,7 @@ static void layerCopy_mdisps(const void *source, void *dest, int count)
|
||||
|
||||
for(i = 0; i < count; ++i) {
|
||||
if(s[i].disps) {
|
||||
d[i].disps = BLI_cellalloc_dupalloc(s[i].disps);
|
||||
d[i].disps = MEM_dupallocN(s[i].disps);
|
||||
d[i].totdisp = s[i].totdisp;
|
||||
}
|
||||
else {
|
||||
@@ -609,7 +608,7 @@ static void layerValidate_mdisps(void *data, int sub_elements)
|
||||
if(corners != sub_elements) {
|
||||
MEM_freeN(disps->disps);
|
||||
disps->totdisp = disps->totdisp / corners * sub_elements;
|
||||
disps->disps = BLI_cellalloc_calloc(3*disps->totdisp*sizeof(float), "layerValidate_mdisps");
|
||||
disps->disps = MEM_callocN(3*disps->totdisp*sizeof(float), "layerValidate_mdisps");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -622,7 +621,7 @@ static void layerFree_mdisps(void *data, int count, int UNUSED(size))
|
||||
|
||||
for(i = 0; i < count; ++i) {
|
||||
if(d[i].disps)
|
||||
BLI_cellalloc_free(d[i].disps);
|
||||
MEM_freeN(d[i].disps);
|
||||
d[i].disps = NULL;
|
||||
d[i].totdisp = 0;
|
||||
}
|
||||
@@ -635,7 +634,7 @@ static int layerRead_mdisps(CDataFile *cdf, void *data, int count)
|
||||
|
||||
for(i = 0; i < count; ++i) {
|
||||
if(!d[i].disps)
|
||||
d[i].disps = BLI_cellalloc_calloc(sizeof(float)*3*d[i].totdisp, "mdisps read");
|
||||
d[i].disps = MEM_callocN(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);
|
||||
|
||||
@@ -45,9 +45,6 @@
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
|
||||
#include "BLI_cellalloc.h"
|
||||
|
||||
|
||||
void defgroup_copy_list(ListBase *outbase, ListBase *inbase)
|
||||
{
|
||||
bDeformGroup *defgroup, *defgroupn;
|
||||
@@ -86,10 +83,10 @@ void defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
|
||||
}
|
||||
else {
|
||||
if (dvert_dst->dw)
|
||||
BLI_cellalloc_free(dvert_dst->dw);
|
||||
MEM_freeN(dvert_dst->dw);
|
||||
|
||||
if (dvert_src->totweight)
|
||||
dvert_dst->dw= BLI_cellalloc_dupalloc(dvert_src->dw);
|
||||
dvert_dst->dw= MEM_dupallocN(dvert_src->dw);
|
||||
else
|
||||
dvert_dst->dw= NULL;
|
||||
|
||||
@@ -587,10 +584,10 @@ MDeformWeight *defvert_verify_index(MDeformVert *dvert, const int defgroup)
|
||||
if (dw_new)
|
||||
return dw_new;
|
||||
|
||||
dw_new= BLI_cellalloc_calloc(sizeof(MDeformWeight)*(dvert->totweight+1), "deformWeight");
|
||||
dw_new= MEM_callocN(sizeof(MDeformWeight)*(dvert->totweight+1), "deformWeight");
|
||||
if (dvert->dw) {
|
||||
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*dvert->totweight);
|
||||
BLI_cellalloc_free(dvert->dw);
|
||||
MEM_freeN(dvert->dw);
|
||||
}
|
||||
dvert->dw= dw_new;
|
||||
dw_new += dvert->totweight;
|
||||
@@ -615,10 +612,10 @@ void defvert_add_index_notest(MDeformVert *dvert, int defgroup, const float weig
|
||||
if (!dvert || defgroup < 0)
|
||||
return;
|
||||
|
||||
dw_new = BLI_cellalloc_calloc(sizeof(MDeformWeight)*(dvert->totweight+1), "defvert_add_to group, new deformWeight");
|
||||
dw_new = MEM_callocN(sizeof(MDeformWeight)*(dvert->totweight+1), "defvert_add_to group, new deformWeight");
|
||||
if(dvert->dw) {
|
||||
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*dvert->totweight);
|
||||
BLI_cellalloc_free(dvert->dw);
|
||||
MEM_freeN(dvert->dw);
|
||||
}
|
||||
dvert->dw = dw_new;
|
||||
dw_new += dvert->totweight;
|
||||
@@ -646,7 +643,7 @@ void defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
|
||||
* this deform weight, and reshuffle the others.
|
||||
*/
|
||||
if (dvert->totweight) {
|
||||
dw_new = BLI_cellalloc_malloc(sizeof(MDeformWeight)*(dvert->totweight), __func__);
|
||||
dw_new = MEM_mallocN(sizeof(MDeformWeight)*(dvert->totweight), __func__);
|
||||
if (dvert->dw) {
|
||||
#if 1 /* since we dont care about order, swap this with the last, save a memcpy */
|
||||
if (i != dvert->totweight) {
|
||||
@@ -657,13 +654,13 @@ void defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
|
||||
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*i);
|
||||
memcpy(dw_new+i, dvert->dw+i+1, sizeof(MDeformWeight)*(dvert->totweight-i));
|
||||
#endif
|
||||
BLI_cellalloc_free(dvert->dw);
|
||||
MEM_freeN(dvert->dw);
|
||||
}
|
||||
dvert->dw = dw_new;
|
||||
}
|
||||
else {
|
||||
/* If there are no other deform weights left then just remove this one. */
|
||||
BLI_cellalloc_free(dvert->dw);
|
||||
MEM_freeN(dvert->dw);
|
||||
dvert->dw = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_editVert.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
#include "BLI_array.h"
|
||||
#include "BLI_edgehash.h"
|
||||
|
||||
@@ -437,7 +436,7 @@ void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount)
|
||||
|
||||
for (i=0; i<copycount; i++){
|
||||
if (src[i].dw){
|
||||
dst[i].dw = BLI_cellalloc_calloc (sizeof(MDeformWeight)*src[i].totweight, "copy_deformWeight");
|
||||
dst[i].dw = MEM_callocN (sizeof(MDeformWeight)*src[i].totweight, "copy_deformWeight");
|
||||
memcpy (dst[i].dw, src[i].dw, sizeof (MDeformWeight)*src[i].totweight);
|
||||
}
|
||||
}
|
||||
@@ -456,7 +455,7 @@ void free_dverts(MDeformVert *dvert, int totvert)
|
||||
|
||||
/* Free any special data from the verts */
|
||||
for (i=0; i<totvert; i++){
|
||||
if (dvert[i].dw) BLI_cellalloc_free (dvert[i].dw);
|
||||
if (dvert[i].dw) MEM_freeN (dvert[i].dw);
|
||||
}
|
||||
MEM_freeN (dvert);
|
||||
}
|
||||
@@ -1897,9 +1896,9 @@ static void bmesh_corners_to_loops(Mesh *me, int findex, int loopstart, int numT
|
||||
ld->totdisp = side*side;
|
||||
|
||||
if (ld->disps)
|
||||
BLI_cellalloc_free(ld->disps);
|
||||
MEM_freeN(ld->disps);
|
||||
|
||||
ld->disps = BLI_cellalloc_calloc(sizeof(float)*3*side*side, "converted loop mdisps");
|
||||
ld->disps = MEM_callocN(sizeof(float)*3*side*side, "converted loop mdisps");
|
||||
if (fd->disps) {
|
||||
memcpy(ld->disps, disps, sizeof(float)*3*side*side);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
#include "BLI_pbvh.h"
|
||||
#include "BLI_editVert.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_mesh.h"
|
||||
@@ -327,10 +326,10 @@ static void multires_reallocate_mdisps(int totloop, MDisps *mdisps, int lvl)
|
||||
/* reallocate displacements to be filled in */
|
||||
for(i = 0; i < totloop; ++i) {
|
||||
int totdisp = multires_grid_tot[lvl];
|
||||
float (*disps)[3] = BLI_cellalloc_calloc(sizeof(float) * 3 * totdisp, "multires disps");
|
||||
float (*disps)[3] = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps");
|
||||
|
||||
if(mdisps[i].disps)
|
||||
BLI_cellalloc_free(mdisps[i].disps);
|
||||
MEM_freeN(mdisps[i].disps);
|
||||
|
||||
mdisps[i].disps = disps;
|
||||
mdisps[i].totdisp = totdisp;
|
||||
@@ -409,7 +408,7 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl)
|
||||
float (*disps)[3], (*ndisps)[3], (*hdisps)[3];
|
||||
int totdisp = multires_grid_tot[lvl];
|
||||
|
||||
disps = BLI_cellalloc_calloc(sizeof(float) * 3 * totdisp, "multires disps");
|
||||
disps = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps");
|
||||
|
||||
ndisps = disps;
|
||||
hdisps = mdisp->disps;
|
||||
@@ -419,7 +418,7 @@ static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl)
|
||||
ndisps += nsize*nsize;
|
||||
hdisps += hsize*hsize;
|
||||
|
||||
BLI_cellalloc_free(mdisp->disps);
|
||||
MEM_freeN(mdisp->disps);
|
||||
mdisp->disps = disps;
|
||||
mdisp->totdisp = totdisp;
|
||||
}
|
||||
@@ -977,7 +976,7 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to)
|
||||
/* when adding new faces in edit mode, need to allocate disps */
|
||||
if(!mdisp->disps) {
|
||||
mdisp->totdisp = gridSize*gridSize;
|
||||
mdisp->disps = BLI_cellalloc_calloc(sizeof(float)*3*mdisp->totdisp, "disp in multires_set_space");
|
||||
mdisp->disps = MEM_callocN(sizeof(float)*3*mdisp->totdisp, "disp in multires_set_space");
|
||||
}
|
||||
|
||||
dispgrid = mdisp->disps;
|
||||
@@ -1179,7 +1178,7 @@ static void old_mdisps_convert(MFace *mface, MDisps *mdisp)
|
||||
int x, y, S;
|
||||
float (*disps)[3], (*out)[3], u = 0.0f, v = 0.0f; /* Quite gcc barking. */
|
||||
|
||||
disps = BLI_cellalloc_calloc(sizeof(float) * 3 * newtotdisp, "multires disps");
|
||||
disps = MEM_callocN(sizeof(float) * 3 * newtotdisp, "multires disps");
|
||||
|
||||
out = disps;
|
||||
for(S = 0; S < nvert; S++) {
|
||||
@@ -1196,7 +1195,7 @@ static void old_mdisps_convert(MFace *mface, MDisps *mdisp)
|
||||
}
|
||||
}
|
||||
|
||||
BLI_cellalloc_free(mdisp->disps);
|
||||
MEM_freeN(mdisp->disps);
|
||||
|
||||
mdisp->totdisp= newtotdisp;
|
||||
mdisp->disps= disps;
|
||||
@@ -1225,7 +1224,7 @@ void multires_load_old_250(Mesh *me)
|
||||
int totdisp = mdisps[i].totdisp / nvert;
|
||||
|
||||
for (j=0; j < mf->v4 ? 4 : 3; j++, k++) {
|
||||
mdisps2[k].disps = BLI_cellalloc_calloc(sizeof(float)*3*totdisp, "multires disp in conversion");
|
||||
mdisps2[k].disps = MEM_callocN(sizeof(float)*3*totdisp, "multires disp in conversion");
|
||||
mdisps2[k].totdisp = totdisp;
|
||||
memcpy(mdisps2[k].disps, mdisps[i].disps + totdisp*j, totdisp);
|
||||
}
|
||||
@@ -2356,13 +2355,13 @@ void mdisp_join_tris(MDisps *dst, MDisps *tri1, MDisps *tri2)
|
||||
MDisps *src;
|
||||
|
||||
if(dst->disps)
|
||||
BLI_cellalloc_free(dst->disps);
|
||||
MEM_freeN(dst->disps);
|
||||
|
||||
side = sqrt(tri1->totdisp / 3);
|
||||
st = (side<<1)-1;
|
||||
|
||||
dst->totdisp = 4 * side * side;
|
||||
out = dst->disps = BLI_cellalloc_calloc(3*dst->totdisp*sizeof(float), "join disps");
|
||||
out = dst->disps = MEM_callocN(3*dst->totdisp*sizeof(float), "join disps");
|
||||
|
||||
for(S = 0; S < 4; S++)
|
||||
for(y = 0; y < side; ++y)
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
#include "BLI_threads.h"
|
||||
#include "BLI_linklist.h"
|
||||
#include "BLI_bpath.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
#include "BLI_math.h"
|
||||
|
||||
#include "BKE_anim.h"
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_linklist.h"
|
||||
#include "BLI_edgehash.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_animsys.h"
|
||||
@@ -3537,7 +3536,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
|
||||
|
||||
if(dvert) {
|
||||
if(!dvert->totweight) {
|
||||
dvert->dw = BLI_cellalloc_calloc(sizeof(MDeformWeight), "deformWeight");
|
||||
dvert->dw = MEM_callocN(sizeof(MDeformWeight), "deformWeight");
|
||||
dvert->totweight = 1;
|
||||
}
|
||||
|
||||
@@ -3558,7 +3557,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
|
||||
|
||||
if(dvert) {
|
||||
if(!dvert->totweight) {
|
||||
dvert->dw = BLI_cellalloc_calloc(sizeof(MDeformWeight), "deformWeight");
|
||||
dvert->dw = MEM_callocN(sizeof(MDeformWeight), "deformWeight");
|
||||
dvert->totweight = 1;
|
||||
}
|
||||
/* roots should be 1.0, the rest can be anything from 0.0 to 1.0 */
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* ***** 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.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2008 by Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
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);
|
||||
@@ -48,7 +48,6 @@ set(SRC
|
||||
intern/BLI_linklist.c
|
||||
intern/BLI_memarena.c
|
||||
intern/BLI_mempool.c
|
||||
intern/BLI_cellalloc.c
|
||||
intern/DLRB_tree.c
|
||||
intern/boxpack2d.c
|
||||
intern/bpath.c
|
||||
@@ -91,7 +90,6 @@ set(SRC
|
||||
intern/winstuff.c
|
||||
|
||||
BLI_array.h
|
||||
BLI_cellalloc.h
|
||||
BLI_smallhash.h
|
||||
BLI_sparsemap.h
|
||||
BLI_args.h
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* ***** 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.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2008 by Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* 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).
|
||||
*/
|
||||
|
||||
#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 */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
|
||||
int size;
|
||||
const char *tag;
|
||||
int idcheck;
|
||||
} MemHeader;
|
||||
|
||||
//#define USE_GUARDEDALLOC
|
||||
|
||||
void *BLI_cellalloc_malloc(int size, const char *tag)
|
||||
{
|
||||
MemHeader *memh;
|
||||
int slot = size + 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*)*(slot+1));
|
||||
if (pools) {
|
||||
memcpy(tmp, pools, totpool*sizeof(void*));
|
||||
}
|
||||
|
||||
pools = tmp;
|
||||
totpool = slot+1;
|
||||
}
|
||||
|
||||
if (!pools[slot]) {
|
||||
pools[slot] = BLI_mempool_create(slot, 1, 128, TRUE, FALSE);
|
||||
}
|
||||
|
||||
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);
|
||||
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 + sizeof(MemHeader);
|
||||
slot += 16 - (slot & 15);
|
||||
|
||||
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, memh->size);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,6 @@
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
#include "BLI_edgehash.h"
|
||||
|
||||
#include "BKE_anim.h"
|
||||
@@ -3733,7 +3732,7 @@ static void direct_link_dverts(FileData *fd, int count, MDeformVert *mdverts)
|
||||
MDeformWeight *dw;
|
||||
if(mdverts->dw && (dw= newdataadr(fd, mdverts->dw))) {
|
||||
const ssize_t dw_len= mdverts->totweight * sizeof(MDeformWeight);
|
||||
void *dw_tmp= BLI_cellalloc_malloc(dw_len, "direct_link_dverts");
|
||||
void *dw_tmp= MEM_mallocN(dw_len, "direct_link_dverts");
|
||||
memcpy(dw_tmp, dw, dw_len);
|
||||
mdverts->dw= dw_tmp;
|
||||
MEM_freeN(dw);
|
||||
@@ -3757,7 +3756,7 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte
|
||||
if (mdisps[i].disps) {
|
||||
float *disp2;
|
||||
|
||||
disp2 = BLI_cellalloc_malloc(MEM_allocN_len(mdisps[i].disps), "cellalloc .disps copy");
|
||||
disp2 = MEM_mallocN(MEM_allocN_len(mdisps[i].disps), "cellalloc .disps copy");
|
||||
memcpy(disp2, mdisps[i].disps, MEM_allocN_len(mdisps[i].disps));
|
||||
|
||||
MEM_freeN(mdisps[i].disps);
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
|
||||
#include "BLI_array.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
|
||||
#include "bmesh.h"
|
||||
#include "bmesh_private.h"
|
||||
@@ -538,7 +537,7 @@ static void bmesh_loop_interp_mdisps(BMesh *bm, BMLoop *target, BMFace *source)
|
||||
|
||||
mdisps->totdisp = md2->totdisp;
|
||||
if (mdisps->totdisp)
|
||||
mdisps->disps = BLI_cellalloc_calloc(sizeof(float)*3*mdisps->totdisp, "mdisp->disps in bmesh_loop_intern_mdisps");
|
||||
mdisps->disps = MEM_callocN(sizeof(float)*3*mdisps->totdisp, "mdisp->disps in bmesh_loop_intern_mdisps");
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
@@ -399,9 +398,9 @@ static void bmesh_set_mdisps_space(BMesh *bm, int from, int to)
|
||||
memcpy(lmd->disps, mdisps->disps, sizeof(float)*3*lmd->totdisp);
|
||||
} else if (mdisps->disps) {
|
||||
if (lmd->disps)
|
||||
BLI_cellalloc_free(lmd->disps);
|
||||
MEM_freeN(lmd->disps);
|
||||
|
||||
lmd->disps = BLI_cellalloc_dupalloc(mdisps->disps);
|
||||
lmd->disps = MEM_dupallocN(mdisps->disps);
|
||||
lmd->totdisp = mdisps->totdisp;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
@@ -362,12 +361,12 @@ int ED_vgroup_copy_array(Object *ob, Object *ob_from)
|
||||
|
||||
for(i=0; i<dvert_tot; i++, dvf++, dv++) {
|
||||
if((*dv)->dw)
|
||||
BLI_cellalloc_free((*dv)->dw);
|
||||
MEM_freeN((*dv)->dw);
|
||||
|
||||
*(*dv)= *(*dvf);
|
||||
|
||||
if((*dv)->dw)
|
||||
(*dv)->dw= BLI_cellalloc_dupalloc((*dv)->dw);
|
||||
(*dv)->dw= MEM_dupallocN((*dv)->dw);
|
||||
}
|
||||
|
||||
MEM_freeN(dvert_array);
|
||||
@@ -1900,7 +1899,7 @@ static void vgroup_delete_edit_mode(Object *ob, bDeformGroup *dg)
|
||||
else if(ob->type==OB_LATTICE) {
|
||||
Lattice *lt= vgroup_edit_lattice(ob);
|
||||
if(lt->dvert) {
|
||||
BLI_cellalloc_free(lt->dvert);
|
||||
MEM_freeN(lt->dvert);
|
||||
lt->dvert= NULL;
|
||||
}
|
||||
}
|
||||
@@ -1952,7 +1951,7 @@ static void vgroup_delete_all(Object *ob)
|
||||
else if(ob->type==OB_LATTICE) {
|
||||
Lattice *lt= vgroup_edit_lattice(ob);
|
||||
if(lt->dvert) {
|
||||
BLI_cellalloc_free(lt->dvert);
|
||||
MEM_freeN(lt->dvert);
|
||||
lt->dvert= NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
#include "BLI_memarena.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_ghash.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
@@ -1634,7 +1633,7 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi,
|
||||
MDeformVert *dv= &me->dvert[index];
|
||||
MDeformVert dv_test= {NULL};
|
||||
|
||||
dv_test.dw= BLI_cellalloc_dupalloc(dv->dw);
|
||||
dv_test.dw= MEM_dupallocN(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
|
||||
@@ -1665,19 +1664,19 @@ static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi,
|
||||
if(tdw->weight != oldw) {
|
||||
if(neww > oldw) {
|
||||
if(tdw->weight <= oldw) {
|
||||
BLI_cellalloc_free(dv_test.dw);
|
||||
MEM_freeN(dv_test.dw);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(tdw->weight >= oldw) {
|
||||
BLI_cellalloc_free(dv_test.dw);
|
||||
MEM_freeN(dv_test.dw);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BLI_cellalloc_free(dv_test.dw);
|
||||
MEM_freeN(dv_test.dw);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -1864,7 +1863,7 @@ static void do_weight_paint_vertex(/* vars which remain the same for every vert
|
||||
|
||||
/* setup multi-paint */
|
||||
if (do_multipaint_totsel) {
|
||||
dv_copy.dw= BLI_cellalloc_dupalloc(dv->dw);
|
||||
dv_copy.dw= MEM_dupallocN(dv->dw);
|
||||
dv_copy.flag = dv->flag;
|
||||
dv_copy.totweight = dv->totweight;
|
||||
tdw = dw;
|
||||
@@ -1918,7 +1917,7 @@ static void do_weight_paint_vertex(/* vars which remain the same for every vert
|
||||
oldChange = 0;
|
||||
}
|
||||
if(dv_copy.dw) {
|
||||
BLI_cellalloc_free(dv_copy.dw);
|
||||
MEM_freeN(dv_copy.dw);
|
||||
}
|
||||
#if 0
|
||||
/* dv may have been altered greatly */
|
||||
|
||||
@@ -65,7 +65,6 @@
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_cellalloc.h"
|
||||
|
||||
#include "RE_engine.h"
|
||||
#include "RE_pipeline.h" /* RE_ free stuff */
|
||||
@@ -444,10 +443,8 @@ void WM_exit_ext(bContext *C, const short do_python)
|
||||
GHOST_DisposeSystemPaths();
|
||||
|
||||
if(MEM_get_memory_blocks_in_use()!=0) {
|
||||
printf("Error: Not freed memory blocks: %d\n", MEM_get_memory_blocks_in_use()+BLI_cellalloc_get_totblock());
|
||||
printf("Error: Not freed memory blocks: %d\n", MEM_get_memory_blocks_in_use());
|
||||
MEM_printmemlist();
|
||||
BLI_cellalloc_printleaks();
|
||||
BLI_cellalloc_destroy();
|
||||
}
|
||||
wm_autosave_delete();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user