Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Susano Pinto <andresusanopinto@gmail.com>2009-08-07 17:49:15 +0400
committerAndre Susano Pinto <andresusanopinto@gmail.com>2009-08-07 17:49:15 +0400
commit51cad12120a673959abfbb1d4445edb782b5f13b (patch)
treeb4947b13ef8e1e0082634c0edf07f7ef65a52ba4 /source/blender/blenlib/intern/BLI_memarena.c
parent20c9f2e8abf5d81e5b8a340b12ff8f6f66eee2ca (diff)
*BLI_memarena support for any power of two alignment
*some simd stuff on bvh
Diffstat (limited to 'source/blender/blenlib/intern/BLI_memarena.c')
-rw-r--r--source/blender/blenlib/intern/BLI_memarena.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c
index 6312cbb22ca..275ab12540b 100644
--- a/source/blender/blenlib/intern/BLI_memarena.c
+++ b/source/blender/blenlib/intern/BLI_memarena.c
@@ -45,6 +45,7 @@ struct MemArena {
int bufsize, cursize;
int use_calloc;
+ int align;
LinkNode *bufs;
};
@@ -52,6 +53,7 @@ struct MemArena {
MemArena *BLI_memarena_new(int bufsize) {
MemArena *ma= MEM_callocN(sizeof(*ma), "memarena");
ma->bufsize= bufsize;
+ ma->align = 8;
return ma;
}
@@ -64,6 +66,11 @@ void BLI_memarena_use_malloc(MemArena *ma) {
ma->use_calloc= 0;
}
+void BLI_memarena_use_align(struct MemArena *ma, int align) {
+ /* align should be a power of two */
+ ma->align = align;
+}
+
void BLI_memarena_free(MemArena *ma) {
BLI_linklist_free(ma->bufs, (void(*)(void*)) MEM_freeN);
MEM_freeN(ma);
@@ -77,16 +84,28 @@ void *BLI_memarena_alloc(MemArena *ma, int size) {
/* ensure proper alignment by rounding
* size up to multiple of 8 */
- size= PADUP(size, 8);
+ size= PADUP(size, ma->align);
if (size>ma->cursize) {
- ma->cursize= (size>ma->bufsize)?size:ma->bufsize;
+ unsigned char *tmp;
+
+ if(size > ma->bufsize - (ma->align - 1))
+ {
+ ma->cursize = PADUP(size+1, ma->align);
+ }
+ else ma->cursize = ma->bufsize;
+
if(ma->use_calloc)
ma->curbuf= MEM_callocN(ma->cursize, "memarena calloc");
else
ma->curbuf= MEM_mallocN(ma->cursize, "memarena malloc");
BLI_linklist_prepend(&ma->bufs, ma->curbuf);
+
+ /* align alloc'ed memory (needed if align > 8) */
+ tmp = (unsigned char*)PADUP( (intptr_t) ma->curbuf, ma->align);
+ ma->cursize -= (tmp - ma->curbuf);
+ ma->curbuf = tmp;
}
ptr= ma->curbuf;