Blender  V3.3
Functions
buffer.c File Reference
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_buffer.h"
#include "BLI_utildefines.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Functions

static voidbuffer_alloc (BLI_Buffer *buffer, const size_t len)
 
static voidbuffer_realloc (BLI_Buffer *buffer, const size_t len)
 
void BLI_buffer_resize (BLI_Buffer *buffer, const size_t new_count)
 
void BLI_buffer_reinit (BLI_Buffer *buffer, const 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)
 

Detailed Description

Primitive generic buffer library.

Usage examples:

BLI_buffer_declare_static(int, my_int_array, BLI_BUFFER_NOP, 32);
BLI_buffer_append(my_int_array, int, 42);
BLI_assert(my_int_array.count == 1);
BLI_assert(BLI_buffer_at(my_int_array, int, 0) == 42);
BLI_buffer_free(&my_int_array);
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_buffer_append(buffer_, type_, val_)
Definition: BLI_buffer.h:50
@ BLI_BUFFER_NOP
Definition: BLI_buffer.h:21
#define BLI_buffer_at(buffer_, type_, index_)
Definition: BLI_buffer.h:36
#define BLI_buffer_declare_static(type_, name_, flag_, static_count_)
Definition: BLI_buffer.h:25
#define BLI_buffer_free(name_)
Definition: BLI_buffer.h:94
Note
this more or less fills same purpose as #BLI_array, but supports resizing the array outside of the function it was declared in.

Definition in file buffer.c.

Function Documentation

◆ _bli_buffer_append_array()

void _bli_buffer_append_array ( BLI_Buffer buffer,
void data,
size_t  count 
)

Append an array of elements.

Callers use BLI_buffer_append_array.

Definition at line 98 of file buffer.c.

References BLI_buffer_resize(), buffer, count, and 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 107 of file buffer.c.

References BLI_BUFFER_USE_STATIC, buffer, 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 75 of file buffer.c.

References BLI_BUFFER_USE_STATIC, buffer, buffer_alloc(), MEM_freeN, and UNLIKELY.

Referenced by pbvh_bmesh_edge_loops().

◆ 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 49 of file buffer.c.

References BLI_BUFFER_USE_STATIC, buffer, buffer_alloc(), buffer_realloc(), and UNLIKELY.

Referenced by _bli_buffer_append_array().

◆ buffer_alloc()

static void* buffer_alloc ( BLI_Buffer buffer,
const size_t  len 
)
static

Definition at line 39 of file buffer.c.

References buffer, len, and MEM_mallocN.

Referenced by BLI_buffer_reinit(), and BLI_buffer_resize().

◆ buffer_realloc()

static void* buffer_realloc ( BLI_Buffer buffer,
const size_t  len 
)
static

Definition at line 44 of file buffer.c.

References buffer, len, and MEM_reallocN_id.

Referenced by BLI_buffer_resize().