Hi, For igraph vectors, one has to distinguish between their _actual_ size (i.e. the number of elements they hold) and their _capacity_ (i.e. the maximum number of elements that they can hold without having to re-allocate the internal memory area that backs the vector). When you call igraph_vector_init, you set the _actual_ size of the vector - so, if you pass N as the vector size, the vector will have N (uninitialized) real elements. What you probably need is to initialize the vector with zero size and then call igraph_vector_reserve(), which increases (or decreases) the _capacity_ of the vector while keeping its size (length) intact.
T. T. On Wed, Sep 9, 2015 at 7:53 PM, Hadidi, Lars <[email protected]> wrote: > When using the igraph_vector_t type, it needs to be initialized with the > function igraph_vector_init, which takes the amount of elements to be > initialized as an argument. The documentation says, that the size of vectors > will be handles automatically by increasing their size on demand, but not > using free when they decrease, in order to keep performance. Therefore, some > internal management must be done. My question is, if it is possible to > overestimate the size of the vector on initialization and assigning elements > less then the initialization size ? Will the internal management keep track > of that, and will the algorithms perform correctly on such vectors. I try to > avoid memory allocation inside the main loop of my program. > > > _______________________________________________ > igraph-help mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/igraph-help > _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
