Blender  V3.3
array_store_utils.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 #include "MEM_guardedalloc.h"
9 
10 #include "BLI_utildefines.h"
11 
12 #include "BLI_array_store.h"
13 #include "BLI_array_store_utils.h" /* own include */
14 
15 #include "BLI_math_base.h"
16 
18  const int stride,
19  const int chunk_size)
20 {
24  sizeof(*bs_stride->stride_table) * stride);
25  }
26  BArrayStore **bs_p = &bs_stride->stride_table[stride - 1];
27 
28  if ((*bs_p) == NULL) {
29  /* calculate best chunk-count to fit a power of two */
30  unsigned int chunk_count = chunk_size;
31  {
32  unsigned int size = chunk_count * stride;
35  chunk_count = size / stride;
36  }
37 
38  (*bs_p) = BLI_array_store_create(stride, chunk_count);
39  }
40  return *bs_p;
41 }
42 
44 {
45  BLI_assert(stride > 0 && stride <= bs_stride->stride_table_len);
46  return bs_stride->stride_table[stride - 1];
47 }
48 
50 {
51  for (int i = 0; i < bs_stride->stride_table_len; i += 1) {
52  if (bs_stride->stride_table[i]) {
54  }
55  }
56 
60 }
61 
63  size_t *r_size_expanded,
64  size_t *r_size_compacted)
65 {
66  size_t size_compacted = 0;
67  size_t size_expanded = 0;
68  for (int i = 0; i < bs_stride->stride_table_len; i++) {
70  if (bs) {
71  size_compacted += BLI_array_store_calc_size_compacted_get(bs);
72  size_expanded += BLI_array_store_calc_size_expanded_get(bs);
73  }
74  }
75 
76  *r_size_expanded = size_expanded;
77  *r_size_compacted = size_compacted;
78 }
Efficient in-memory storage of multiple similar arrays.
size_t BLI_array_store_calc_size_expanded_get(const BArrayStore *bs)
Definition: array_store.c:1469
BArrayStore * BLI_array_store_create(unsigned int stride, unsigned int chunk_count)
Definition: array_store.c:1388
void BLI_array_store_destroy(BArrayStore *bs)
Definition: array_store.c:1441
size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs)
Definition: array_store.c:1478
#define BLI_assert(a)
Definition: BLI_assert.h:46
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:75
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
static const int chunk_size
struct BArrayStore ** stride_table