| 42 | */ |
| 43 | |
| 44 | my_bool init_dynamic_array2(PSI_memory_key psi_key, DYNAMIC_ARRAY *array, |
| 45 | size_t element_size, void *init_buffer, |
| 46 | size_t init_alloc, size_t alloc_increment, |
| 47 | myf my_flags) |
| 48 | { |
| 49 | DBUG_ENTER("init_dynamic_array2"); |
| 50 | if (!alloc_increment) |
| 51 | { |
| 52 | alloc_increment=MY_MAX((8192-MALLOC_OVERHEAD)/element_size,16); |
| 53 | if (init_alloc > 8 && alloc_increment > init_alloc * 2) |
| 54 | alloc_increment=init_alloc*2; |
| 55 | } |
| 56 | array->elements=0; |
| 57 | array->max_element=init_alloc; |
| 58 | array->alloc_increment=alloc_increment; |
| 59 | array->size_of_element=element_size; |
| 60 | array->m_psi_key= psi_key; |
| 61 | array->malloc_flags= my_flags; |
| 62 | DBUG_ASSERT((my_flags & MY_INIT_BUFFER_USED) == 0); |
| 63 | if ((array->buffer= init_buffer)) |
| 64 | { |
| 65 | array->malloc_flags|= MY_INIT_BUFFER_USED; |
| 66 | DBUG_RETURN(FALSE); |
| 67 | } |
| 68 | /* |
| 69 | Since the dynamic array is usable even if allocation fails here malloc |
| 70 | should not throw an error |
| 71 | */ |
| 72 | if (init_alloc && |
| 73 | !(array->buffer= (uchar*) my_malloc(psi_key, element_size*init_alloc, |
| 74 | MYF(my_flags)))) |
| 75 | array->max_element=0; |
| 76 | DBUG_RETURN(FALSE); |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | Insert element at the end of array. Allocate memory if needed. |
no test coverage detected