Blender  V2.93
BLI_array.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  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
49 #include <string.h>
50 
51 #include "BLI_array.h"
52 
53 #include "BLI_sys_types.h"
54 
55 #include "MEM_guardedalloc.h"
56 
62 void _bli_array_grow_func(void **arr_p,
63  const void *arr_static,
64  const int sizeof_arr_p,
65  const int arr_len,
66  const int num,
67  const char *alloc_str)
68 {
69  void *arr = *arr_p;
70  void *arr_tmp;
71 
72  arr_tmp = MEM_mallocN(sizeof_arr_p * ((num < arr_len) ? (arr_len * 2 + 2) : (arr_len + num)),
73  alloc_str);
74 
75  if (arr) {
76  memcpy(arr_tmp, arr, sizeof_arr_p * arr_len);
77 
78  if (arr != arr_static) {
79  MEM_freeN(arr);
80  }
81  }
82 
83  *arr_p = arr_tmp;
84 }
void _bli_array_grow_func(void **arr_p, const void *arr_static, const int sizeof_arr_p, const int arr_len, const int num, const char *alloc_str)
Definition: BLI_array.c:62
A (mainly) macro array library.
Read Guarded memory(de)allocation.
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47