DESCRIBE and sqlda struct
Posted in 1994
Jonathan Leffler writes: |> De-allocation of this space is a vexed subject for me, and without having |> the time to re-check my memory, I think the behaviour has changed at |> several releases, and I don't remember exactly which releases do what. |> However, I think that release 5.00 would release the space for you when you |> re-executed the DESCRIBE, and if you did the release for it, all hell broke |> loose in malloc() and friends. As far as I can tell, 5.01 expects you to |> release the memory, but that needs re-checking. I think 4.0x and 4.1x |> expected you to release the memory too, along with 2.10.03, 2.10.00, and |> other earlier versions. When I find time to sort out my main ESQL/C |> command interpreter, there is going to be a #define for FREE_DESCRIBED_SQLDA |> or something similar to handle the differences between versions. Another way to use sqlda in 5.0 is to use ALLOCATE DESCRIPTOR, which will essentially allocate an array of descriptor structures which you can then configure as needed (unlike describe, it will not fill in the descriptive fields for you; on the other hand, it does not require a select statment for use, so you can use it for input variables as well). In this case, cleaning them up is done via the DEALLOCATE DESCRIPTOR command. The nice thing with regards to the DESCIBE statement is that you can allocate descriptors, then DESCRIBE USING that allocated descriptor. You could then either use the DEALLOCATE command to clean it up when you are done, or just keep them around for the next time you needed them. In either case, since the data pointer needs to be "filled in", any memory allocated for the data buffer for each descriptor must be freed using free() independently of the deallocate. Note that DESCRIBE will NOT allocate the space for that data field either; you must malloc and free that space yourself (unless, of course, you are using declared variables and just pointing at them). Dave Disclaimer: These opinions are not those of Informix Software, Inc. ************************************************************************** "I look back with some satisfaction on what an idiot I was when I was 25, but when I do that, I'm assuming I'm no longer an idiot." - Andy Rooney