igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] How to test for initialisation?


From: Gábor Csárdi
Subject: Re: [igraph] How to test for initialisation?
Date: Tue, 21 Jan 2014 09:27:55 -0500

Hi, 

in general there is no way to decide. You need to keep track of it yourself. If you have some dynamic data structure, e.g. a list of graphs, some initialized, some not, then create a structure like this:

typedef struct myigraph_t {
  igraph_t graph;
  igraph_bool_t inited;
} myigraph_t;

You need to make sure that you explicitly set 'inited' to false (0), when you create a new myigraph_t, because by default its value is undefined. (This is exactly why you cannot know if an igraph_t was initialized or not.)

Alternatively, you can create an igraph_vector_bool_t, with one element corresponding to each graph in your list. When you call igraph_vector_bool_init() on it, all elements are set to zero automatically. (But not if you resize it!).

These solutions might not work for you exactly, but hopefully you got the idea and can adapt them to your case.

Best,
Gabor


On Tue, Jan 21, 2014 at 4:24 AM, Timothy Rice <address@hidden> wrote:
Hello,

How can I test whether an igraph_t variable has been initialised already?

I'm getting a segfault when I call igraph_destroy on an uninitialised
graph. I would have expected that igraph_destroy would simply not do
anything in this case, but given that igraph_destroy seems to assume a
pre-initialised graph, how can I avoid the segfault?

It's not possible for me to know at compile-time whether the graph in
question has been initialised. It depends on user input, which selects
between various graph operations using function pointers. Most of these
function pointers result in an initialised graph, but sometimes not.
Regardless of user input, I'd like to ensure I destroy all graphs whenever
they exist before the program exits.

If my meaning isn't clear and you need some example minimal code, let me
know and I'll see what I can cook up :-)


Cheers,


Tim Rice
--
PhD Candidate
A: Room 210, Richard Berry (Maths & Stats), Melbourne University
E: address@hidden
W: http://www.ms.unimelb.edu.au/~trice

_______________________________________________
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]