igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Proper way to deal with igraph_vector_ptr_t returned by fun


From: Gábor Csárdi
Subject: Re: [igraph] Proper way to deal with igraph_vector_ptr_t returned by functions
Date: Tue, 8 Dec 2015 14:21:25 +0000

Hi, answers below.

On Fri, Sep 11, 2015 at 10:48 PM, Szabolcs Horvát <address@hidden> wrote:
[...]
> Do all these igraph functions (e.g. igraph_cliques) handle pointer
> vectors in the same way?

I doubt it. Some of them were written earlier, and some things, e.g.
the _free_all() method are newer.

> In particular, do they have destructors set
> already?  Perhaps some functions set destructors and some don't? Do
> all require already initialized pointer vectors?

I cannot tell you, I would need to go and look. Usually functions
assume that the vectors passed as arguments are initialized. But
whether the contents of the ptr vector are initialized is a different
question.

> Roughly, this is what I'm doing:
>
> igraph_vector_ptr_t list;
>
> igraph_vector_ptr_init(&list, 0);
>
> // make sure the right destructor is set
> IGRAPH_VECTOR_PTR_SET_ITEM_DESTRUCTOR(&list, igraph_vector_destroy);
>
> igraph_some_function(..., &list, ...);
>
> // use list in some way ...
>
> // this should free
> igraph_vector_ptr_destroy_all(&list);
>
> Is this way general enough to handle *any* igraph function that
> returns multiple vectors this way?

Might not be. I would read the documentation of igraph_some_function

> Instead of setting a destructor, I could loop through it and free
> elements by hand. Some examples do that.

That was before Tamas added the destroy_all() method.

> Finally, I notice that some examples use free() and not igraph_free()
> to free memory. Do I need to worry about this and the potential
> differences between the two if igraph itself and my program use
> different compilers?  Shouldn't igraph provide an igraph_malloc in
> addition to igraph_free to make sure that memory I might allocate will
> be correctly freed by igraph_vector_ptr_free_all()? This last one is
> so far a theoretical question as I don't yet need this.

Don't worry about free and igraph_free. AFAIR igraph_free is newer,
and the idea was that we could use different allocators, but in the
end we never did this.

I guess we could still convert all free() to igraph_free()

GAbor

> Szabolcs
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help



reply via email to

[Prev in Thread] Current Thread [Next in Thread]