Hi Tariq,
> I am a new member on this forum. I have recently started using mysql
Welcome!
> udf. The code that i am implementing requires me to get the value of
> input parameters from 'init' function and use them to fill an array
> based on the input parameters in 'clear' function. Now the problem is
> that 'clear' function does not provide UDF_ARGS *args arguments, so
> what I am doing is that creating a global pointer variable and
> assigning the value of UDF_ARGS *args to that global variable in
> 'init' function. Now I can use this global variable to access input
This is asking for trouble...You can only use static globals to hold
some immutable data. Or at the very least you must prevent at all cost
multiple threads accessing those globals (locking)
In short, this is not the way to go.
THe correct way doing this is to use the ptr member of the UDF_INITID
struct, like so:
initid->ptr = malloc(numbytes);
FOr most functions it is ok to alloc mem just once in the INIT
function, but nothing prevents you from doing it whenever and in
whatever function you like. Note that the UDF_INITID struct is passed
to all functions that make up the UDF interface.
Deallocating memory should be done in the XXX_deinit function.
Note that if you alloc mem in the XXX_init function and accidentally
have an error there, the XXX_deinit function will *not* be called -
meaning you will have to clean up there too.
kind regards,
I hope it helps.