[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Destroying uninitialized graphs
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] Destroying uninitialized graphs |
Date: |
Tue, 8 Mar 2011 00:10:20 -0500 |
Matthew,
I somehow don't like this idea. I think the user should keep track of
what (s)he initializes and (s)he doesn't. The igraph_zero function
would just discourage this. I haven't seen such functions in other
libraries that are similar to igraph, e.g. GSL, either.
You can always write such a function for yourself, and you can write
your own destroy function as well, if you like, they are both very
simple:
void igraph_zero(igraph_t *graph) {
memset(graph, 0, sizeof(igraph_t));
}
void igraph_mydestroy(igraph_t *graph) {
char *c= (char*) graph;
int i;
for (i=0; i<sizeof(igraph_t); i++) {
if (*c) { igraph_destroy(graph); return; }
c++;
}
}
(Untested, sorry.)
Best Regards,
Gabor
On Mon, Mar 7, 2011 at 6:30 PM, Matthew Walker
<address@hidden> wrote:
> Hi Gabor, Tamas,
>
> Thanks again for your suggestions.
>
> I cannot help but ask, why isn't this approach available inside igraph?
>
> There could be an igraph_zero() function, that just zero'd the memory used
> in igraph_t. Such a function would mean that igraph_destroy() could then be
> made safe to call on zero'd graphs.
>
> Thanks again,
>
> Matthew
>
> On 11-03-07 10:34 AM, Gábor Csárdi wrote:
>>
>> Matthew,
>>
>> there is no such function. You need to keep track of that. It is
>> actually not possible to write such a function, IMHO, because some
>> architectures do not zero out newly allocated memory. Although,
>> probably most of the do, nowadays.
>>
>> What you can do, is filling the igraph_t by zeros after you allocate
>> it, and then check whether the 'from' field is zero or not. It should
>> not be zero for a valid graph.
>>
>> Best,
>> Gabor
>>
>> On Mon, Mar 7, 2011 at 10:28 AM, Matthew Walker
>> <address@hidden> wrote:
>>>
>>> Hi,
>>>
>>> I currently have a problem in that my program seg faults because I am
>>> calling igraph_destroy() on an uninitialized graph.
>>>
>>> Is there a function to tell whether the graph is initialized?
>>>
>>> Thanks,
>>>
>>> Matthew
>>>
>>> _______________________________________________
>>> igraph-help mailing list
>>> address@hidden
>>> http://lists.nongnu.org/mailman/listinfo/igraph-help
>>>
>>
>>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
--
Gabor Csardi <address@hidden> UNIL DGM