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:
Diffstat (limited to 'source/blender/blenlib/intern/buffer.c')
-rw-r--r--source/blender/blenlib/intern/buffer.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/buffer.c b/source/blender/blenlib/intern/buffer.c
index 7588a6ec14d..6ab57221a63 100644
--- a/source/blender/blenlib/intern/buffer.c
+++ b/source/blender/blenlib/intern/buffer.c
@@ -102,6 +102,37 @@ void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count)
buffer->count = new_count;
}
+/**
+ * Similar to #BLI_buffer_resize, but use when the existing data can be:
+ * - Ignored (malloc'd)
+ * - Cleared (when BLI_BUFFER_USE_CALLOC is set)
+ */
+void BLI_buffer_reinit(BLI_Buffer *buffer, size_t new_count)
+{
+ if (UNLIKELY(new_count > buffer->alloc_count)) {
+ if ((buffer->flag & BLI_BUFFER_USE_STATIC) == 0) {
+ MEM_freeN(buffer->data);
+ }
+
+ if (buffer->alloc_count && (new_count < buffer->alloc_count * 2)) {
+ buffer->alloc_count *= 2;
+ }
+ else {
+ buffer->alloc_count = new_count;
+ }
+
+ buffer->data = buffer_alloc(buffer, new_count);
+ }
+ else {
+ if (buffer->flag & BLI_BUFFER_USE_CALLOC) {
+ memset(buffer->data, 0,
+ buffer->elem_size * new_count);
+ }
+ }
+
+ buffer->count = new_count;
+}
+
/* callers use BLI_buffer_free */
void _bli_buffer_free(BLI_Buffer *buffer)
{