Memory Allocation

[This is preliminary documentation and subject to change.]

Ownership of command trees may be transferred via several different methods in OLE-DB. A transfer of ownership occurs when a component that allocates a command tree is no longer responsible for freeing the allocated resources. For example, command trees may be obtained by consumers via, ICommand::GetCommandTree. In order for this transfer to be successful, a standard for allocation and deallocation must be identified.

In general, the standard OLE Task Allocator interface, obtained by calling CoGetMalloc should be used for allocation and release of the memory. DBCOMMANDTREE nodes and the values embedded therein are allocated using IMalloc::Alloc and released via IMalloc::Free, with the following exceptions:

All other pointers embedded in a command tree are assumed to have been dynamically allocated with IMalloc::Alloc and will be released with IMalloc::Free.

When allocating a tree that will not change ownership, any method of allocation is acceptable except for the three exception cases listed above since those values also have special copy functions.

Providers should have separate allocations for the fixed (24 bytes) and the variable parts of the node to reduce memory fragmentation and to enable in place substitution of values in the node.