Blender V4.3
BLI_buffer.h File Reference

Go to the source code of this file.

Classes

struct  BLI_Buffer
 

Macros

#define BLI_buffer_declare_static(type_, name_, flag_, static_count_)
 
#define BLI_buffer_declare(type_, name_, flag_)
 
#define BLI_buffer_at(buffer_, type_, index_)
 
#define BLI_buffer_array(buffer_, type_)   (&(BLI_buffer_at(buffer_, type_, 0)))
 
#define BLI_buffer_resize_data(buffer_, type_, new_count_)    ((BLI_buffer_resize(buffer_, new_count_), new_count_ ? BLI_buffer_array(buffer_, type_) : NULL))
 
#define BLI_buffer_reinit_data(buffer_, type_, new_count_)    ((BLI_buffer_reinit(buffer_, new_count_), new_count_ ? BLI_buffer_array(buffer_, type_) : NULL))
 
#define BLI_buffer_append(buffer_, type_, val_)
 
#define BLI_buffer_clear(buffer_)
 
#define BLI_buffer_append_array(buffer_, type_, data_, count_)
 
#define BLI_buffer_free(name_)
 
#define BLI_buffer_field_init(name_, type_)
 
#define BLI_buffer_field_free(name_)   _bli_buffer_free(name_)
 

Typedefs

typedef struct BLI_Buffer BLI_Buffer
 

Enumerations

enum  { BLI_BUFFER_NOP = 0 , BLI_BUFFER_USE_STATIC = (1 << 0) }
 

Functions

void BLI_buffer_resize (BLI_Buffer *buffer, size_t new_count)
 
void BLI_buffer_reinit (BLI_Buffer *buffer, size_t new_count)
 
void _bli_buffer_append_array (BLI_Buffer *buffer, void *new_data, size_t count)
 
void _bli_buffer_free (BLI_Buffer *buffer)
 

Macro Definition Documentation

◆ BLI_buffer_append

#define BLI_buffer_append ( buffer_,
type_,
val_ )
Value:
((BLI_buffer_resize(buffer_, (buffer_)->count + 1), \
(BLI_buffer_at(buffer_, type_, (buffer_)->count - 1) = val_)))
#define BLI_buffer_at(buffer_, type_, index_)
Definition BLI_buffer.h:38
void BLI_buffer_resize(BLI_Buffer *buffer, size_t new_count)
Definition buffer.c:51
int count

Definition at line 52 of file BLI_buffer.h.

Referenced by bm_face_split_by_edges(), BM_mesh_separate_faces(), raycast_callback(), sph_force_cb(), and wm_gizmogroup_intersectable_gizmos_to_list().

◆ BLI_buffer_append_array

#define BLI_buffer_append_array ( buffer_,
type_,
data_,
count_ )
Value:
{ \
type_ *__tmp = (data_); \
BLI_assert(sizeof(type_) == (buffer_)->elem_size); \
_bli_buffer_append_array(buffer_, __tmp, count_); \
} \
(void)0

Definition at line 82 of file BLI_buffer.h.

Referenced by dynamics_step_sphdata_reduce().

◆ BLI_buffer_array

#define BLI_buffer_array ( buffer_,
type_ )   (&(BLI_buffer_at(buffer_, type_, 0)))

Definition at line 44 of file BLI_buffer.h.

◆ BLI_buffer_at

#define BLI_buffer_at ( buffer_,
type_,
index_ )
Value:
((((type_ *)(buffer_) \
->data)[((BLI_assert(sizeof(type_) == (buffer_)->elem_size)), \
(BLI_assert((int)(index_) >= 0 && (size_t)(index_) < (buffer_)->count)), \
index_)]))
#define BLI_assert(a)
Definition BLI_assert.h:50

Definition at line 38 of file BLI_buffer.h.

Referenced by dynamics_step_sphdata_reduce(), and psys_sph_flush_springs().

◆ BLI_buffer_clear

#define BLI_buffer_clear ( buffer_)
Value:
{ \
(buffer_)->count = 0; \
} \
(void)0

Definition at line 56 of file BLI_buffer.h.

Referenced by bm_face_split_by_edges(), and BM_mesh_separate_faces().

◆ BLI_buffer_declare

#define BLI_buffer_declare ( type_,
name_,
flag_ )
Value:
bool name_##user; /* warn for free only */ \
BLI_Buffer name_ = {NULL, sizeof(type_), 0, 0, (flag_)}
#define NULL

Definition at line 34 of file BLI_buffer.h.

◆ BLI_buffer_declare_static

#define BLI_buffer_declare_static ( type_,
name_,
flag_,
static_count_ )
Value:
char name_##user; /* warn for free only */ \
type_ name_##_static_[static_count_]; \
BLI_Buffer name_ = { \
(name_##_static_), sizeof(type_), 0, static_count_, BLI_BUFFER_USE_STATIC | (flag_)}
@ BLI_BUFFER_USE_STATIC
Definition BLI_buffer.h:24

Definition at line 27 of file BLI_buffer.h.

Referenced by BKE_mesh_uv_vert_map_create(), BM_mesh_separate_faces(), edbm_face_split_by_edges_exec(), isect_bvhtree_point_v3(), solidify_add_thickness(), and wm_gizmomap_highlight_find().

◆ BLI_buffer_field_free

#define BLI_buffer_field_free ( name_)    _bli_buffer_free(name_)

Definition at line 113 of file BLI_buffer.h.

Referenced by dynamics_step_sphdata_reduce(), and psys_sph_flush_springs().

◆ BLI_buffer_field_init

#define BLI_buffer_field_init ( name_,
type_ )
Value:
{ \
memset((void *)name_, 0, sizeof(*name_)); \
*(size_t *)&((name_)->elem_size) = sizeof(type_); \
} \
(void)0

A buffer embedded in a struct. Using #memcpy is allowed until first resize.

Definition at line 106 of file BLI_buffer.h.

Referenced by psys_sph_init().

◆ BLI_buffer_free

#define BLI_buffer_free ( name_)
Value:
{ \
_bli_buffer_free(name_); \
(void)name_##user; /* ensure we free */ \
} \
(void)0

Definition at line 96 of file BLI_buffer.h.

Referenced by BKE_mesh_uv_vert_map_create(), BM_mesh_separate_faces(), edbm_face_split_by_edges_exec(), isect_bvhtree_point_v3(), solidify_add_thickness(), and wm_gizmomap_highlight_find().

◆ BLI_buffer_reinit_data

#define BLI_buffer_reinit_data ( buffer_,
type_,
new_count_ )    ((BLI_buffer_reinit(buffer_, new_count_), new_count_ ? BLI_buffer_array(buffer_, type_) : NULL))

Definition at line 49 of file BLI_buffer.h.

Referenced by BKE_mesh_uv_vert_map_create(), and solidify_add_thickness().

◆ BLI_buffer_resize_data

#define BLI_buffer_resize_data ( buffer_,
type_,
new_count_ )    ((BLI_buffer_resize(buffer_, new_count_), new_count_ ? BLI_buffer_array(buffer_, type_) : NULL))

Definition at line 46 of file BLI_buffer.h.

Typedef Documentation

◆ BLI_Buffer

typedef struct BLI_Buffer BLI_Buffer

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BLI_BUFFER_NOP 
BLI_BUFFER_USE_STATIC 

Definition at line 22 of file BLI_buffer.h.

Function Documentation

◆ _bli_buffer_append_array()

void _bli_buffer_append_array ( BLI_Buffer * buffer,
void * new_data,
size_t count )

Append an array of elements.

Callers use BLI_buffer_append_array.

Definition at line 100 of file buffer.c.

References BLI_buffer_resize(), BLI_Buffer::count, count, BLI_Buffer::data, and BLI_Buffer::elem_size.

◆ _bli_buffer_free()

void _bli_buffer_free ( BLI_Buffer * buffer)

Does not free the buffer structure itself.

Callers use BLI_buffer_free.

Definition at line 109 of file buffer.c.

References BLI_BUFFER_USE_STATIC, BLI_Buffer::data, BLI_Buffer::flag, and MEM_freeN().

◆ BLI_buffer_reinit()

void BLI_buffer_reinit ( BLI_Buffer * buffer,
size_t new_count )

Ensure size, throwing away old data, respecting #BLI_BUFFER_USE_CALLOC.

Similar to BLI_buffer_resize, but use when the existing data can be:

  • Ignored (malloc'd).
  • Cleared (when #BLI_BUFFER_USE_CALLOC is set).

Definition at line 77 of file buffer.c.

References BLI_Buffer::alloc_count, BLI_BUFFER_USE_STATIC, buffer_alloc(), BLI_Buffer::count, BLI_Buffer::data, BLI_Buffer::flag, MEM_freeN(), and UNLIKELY.

◆ BLI_buffer_resize()

void BLI_buffer_resize ( BLI_Buffer * buffer,
size_t new_count )
Note
Never decreases the amount of memory allocated.

Definition at line 51 of file buffer.c.

References BLI_Buffer::alloc_count, BLI_BUFFER_USE_STATIC, buffer_alloc(), buffer_realloc(), BLI_Buffer::count, BLI_Buffer::data, BLI_Buffer::elem_size, BLI_Buffer::flag, and UNLIKELY.

Referenced by _bli_buffer_append_array().