1
0
mirror of https://github.com/MariaDB/server.git synced 2025-10-12 12:25:37 +03:00

Added a delete_function for DYNAMIC_ARRAY.

The function calls delete_dynamic, after if calls a free function on every
array element.
This commit is contained in:
Vicențiu Ciorbaru
2013-10-17 15:03:04 -07:00
committed by Sergei Golubchik
parent 9e7228dc4a
commit 89229fb71c
2 changed files with 20 additions and 0 deletions

View File

@@ -335,6 +335,9 @@ struct st_my_file_info
extern struct st_my_file_info *my_file_info;
/* Free function pointer */
typedef void (*FREE_FUNC)(void *);
typedef struct st_dynamic_array
{
uchar *buffer;

View File

@@ -321,7 +321,24 @@ void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx)
(array->elements-idx)*array->size_of_element);
}
/*
Wrapper around delete_dynamic, calling a FREE function on every
element, before releasing the memory
SYNOPSIS
delete_dynamic_recursive()
array
f The function to be called on every element before
deleting the array;
*/
void delete_dynamic_recursive(DYNAMIC_ARRAY *array, FREE_FUNC f) {
uint i;
char *ptr= (char*) array->buffer;
for (i= 0; i < array->elements; i++, ptr+= array->size_of_element) {
f(ptr);
}
delete_dynamic(array);
}
/*
Free unused memory