Oracle FAQ Your Portal to the Oracle Knowledge Grid

Home -> Community -> Usenet -> c.d.o.server -> Re: OCI, binding and memory usage

Re: OCI, binding and memory usage

From: Kevin English <>
Date: Sat, 13 Jul 2002 08:57:08 -0600
Message-ID: <>

On 8 Jul 2002 08:31:28 -0700, (Eric) wrote:

>I'm a relative newcomer to OCI 8 programming. I am confused by some
>of the OCI documentation, specifically related to OCIBindByPos.
>What I want to do is this:
>- prepare a PL/SQL statement once
>- bind input and output to program variables; for each execution of
>the statement, the location of the bind variables may be different
>- execute the statement many times
>It's unclear what happens with regard to allocation and deallocation
>of the *bindpp variables. The documentation implies that each time
>OCIBindByPos is called, a bindpp struct will be allocated, and that
>once the statement handle is freed, all associated bindpp structs are
>also freed.
>Assume I have one variable to bind in the statement, and I need to
>execute the statement 1 million times, storing the result in different
>places each time (or at least, unpredictable memory locations each
>time, probably some overlap). So I call OCIBindByPos 1 million
>times...does this mean OCI will allocate the bindpp 1 million times?
>And is OCIHandleFree really smart enough to free the bindpp pointers
>for all 1 million cases, or just the last one?
>Very confusing. All I want to do is really change the location of
>each parameter in memory, and nothing else. The statement remains the
> same, the parameters remain the same, the data types remain the same.

You don't need to realloc the bind handle each time. OCI will allocate a handle only if you pass NULL in as the bindpp. Use this same handle each time you call OCIBindByPos() and you won't have any worries.
On my Linux system, it appears that even if you use NULL for the bindpp, successive OCIBindByPos() calls on the same stmt handle for the same pos result in OCI returning the same bind handle, without any memory leakage. However, I don't know if you can always count on this behaviour.

Kevin English

 Posted Via Premium Usenet Newsgroup Services

Received on Sat Jul 13 2002 - 09:57:08 CDT

Original text of this message