Commit 89229fb7 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru Committed by Sergei Golubchik

Added a delete_function for DYNAMIC_ARRAY.

The function calls delete_dynamic, after if calls a free function on every
array element.
parent 9e7228dc
......@@ -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;
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment