tdb and ldb

simo idra at samba.org
Fri Feb 3 16:12:31 MST 2012


On Sat, 2012-02-04 at 07:01 +1030, Rusty Russell wrote:
>  /**
> + * struct tdb_attribute_allocator - allocator for tdb to use.
> + *
> + * You can replace malloc/free with your own allocation functions.
> + * The allocator takes an "owner" pointer, which is either NULL (for
> + * the initial struct tdb_context and struct tdb_file), or a
> + * previously allocated pointer.  This is useful for relationship
> + * tracking, such as the talloc library.
> + *
> + * The expand function is realloc, but only ever used to expand an
> + * existing allocation.
> + *
> + * Be careful mixing allocators: two tdb_contexts which have the same
> file
> + * open will share the same struct tdb_file.  This may be allocated
> by one
> + * tdb's allocator, and freed by the other.
> + */
> +struct tdb_attribute_allocator {
> +       struct tdb_attribute_base base; /* .attr =
> TDB_ATTRIBUTE_ALLOCATOR */
> +       void *(*alloc)(const void *owner, size_t len);
> +       void *(*expand)(void *old, size_t newlen);
> +       void (*free)(void *old);
> +};
> +
> +/** 

If you want this to be really generic you should pass the void * pointer
to all routines. When you use allocation pools you may need the pool
also to do the expand and the free as the information about the pool may
not be embedded in the pointer.

Simo.

-- 
Simo Sorce
Samba Team GPL Compliance Officer <simo at samba.org>
Principal Software Engineer at Red Hat, Inc. <simo at redhat.com>



More information about the samba-technical mailing list