igraph-help
[Top][All Lists]
Advanced

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

[igraph] Proper way to deal with igraph_vector_ptr_t returned by functio


From: Szabolcs Horvát
Subject: [igraph] Proper way to deal with igraph_vector_ptr_t returned by functions
Date: Fri, 11 Sep 2015 23:48:11 +0200

Hi all,

Many igraph functions return "lists of lists" as an
igraph_vector_ptr_t of igraph_vector_t * elements. This question is
only about cases when the pointer vector contains pointers to
igraph_vector_t.

I'm looking for some confirmation that I am dealing with these in the
right way and that I am freeing memory properly.

First question:

Do all these igraph functions (e.g. igraph_cliques) handle pointer
vectors in the same way?  In particular, do they have destructors set
already?  Perhaps some functions set destructors and some don't? Do
all require already initialized pointer vectors?

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?

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

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.

Szabolcs



reply via email to

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