Blender  V2.93
array_store_utils.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include "MEM_guardedalloc.h"
23 
24 #include "BLI_utildefines.h"
25 
26 #include "BLI_array_store.h"
27 #include "BLI_array_store_utils.h" /* own include */
28 
29 #include "BLI_math_base.h"
30 
32  const int stride,
33  const int chunk_size)
34 {
38  sizeof(*bs_stride->stride_table) * stride);
39  }
40  BArrayStore **bs_p = &bs_stride->stride_table[stride - 1];
41 
42  if ((*bs_p) == NULL) {
43  /* calculate best chunk-count to fit a power of two */
44  unsigned int chunk_count = chunk_size;
45  {
46  unsigned int size = chunk_count * stride;
49  chunk_count = size / stride;
50  }
51 
52  (*bs_p) = BLI_array_store_create(stride, chunk_count);
53  }
54  return *bs_p;
55 }
56 
58 {
59  BLI_assert(stride > 0 && stride <= bs_stride->stride_table_len);
60  return bs_stride->stride_table[stride - 1];
61 }
62 
64 {
65  for (int i = 0; i < bs_stride->stride_table_len; i += 1) {
66  if (bs_stride->stride_table[i]) {
68  }
69  }
70 
74 }
75 
77  size_t *r_size_expanded,
78  size_t *r_size_compacted)
79 {
80  size_t size_compacted = 0;
81  size_t size_expanded = 0;
82  for (int i = 0; i < bs_stride->stride_table_len; i++) {
84  if (bs) {
85  size_compacted += BLI_array_store_calc_size_compacted_get(bs);
86  size_expanded += BLI_array_store_calc_size_expanded_get(bs);
87  }
88  }
89 
90  *r_size_expanded = size_expanded;
91  *r_size_compacted = size_compacted;
92 }
Efficient in-memory storage of multiple similar arrays.
size_t BLI_array_store_calc_size_expanded_get(const BArrayStore *bs)
Definition: array_store.c:1512
BArrayStore * BLI_array_store_create(unsigned int stride, unsigned int chunk_count)
Definition: array_store.c:1422
void BLI_array_store_destroy(BArrayStore *bs)
Definition: array_store.c:1478
size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs)
Definition: array_store.c:1525
#define BLI_assert(a)
Definition: BLI_assert.h:58
MINLINE unsigned int power_of_2_max_u(unsigned int x)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
Read Guarded memory(de)allocation.
#define MEM_recallocN(vmemh, len)
#define MEM_SIZE_OPTIMAL(size)
void BLI_array_store_at_size_clear(struct BArrayStore_AtSize *bs_stride)
void BLI_array_store_at_size_calc_memory_usage(struct BArrayStore_AtSize *bs_stride, size_t *r_size_expanded, size_t *r_size_compacted)
BArrayStore * BLI_array_store_at_size_ensure(struct BArrayStore_AtSize *bs_stride, const int stride, const int chunk_size)
BArrayStore * BLI_array_store_at_size_get(struct BArrayStore_AtSize *bs_stride, const int stride)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
struct BArrayStore_AtSize bs_stride
Definition: editfont_undo.c:89
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
struct BArrayStore ** stride_table