[SimGrid-user] Dynar issues

Christophe ENDERLIN c.enderlin at me.com
Tue Feb 12 23:02:54 CET 2013


I'm currently facing some troubles with dynars. Here is a small example.

I declared one dynar this way:

typedef struct node_rep {                                               
	int id;
	char mailbox[MAILBOX_NAME_SIZE];
} s_node_rep_t, *node_rep_t;

me->cnx_req_queue = xbt_dynar_new_sync(sizeof(node_rep_t), &xbt_free_ref);

Then, I add some entries to that dynar:

node_rep_t cnx_elem = xbt_new0(s_node_rep_t, 1);              
cnx_elem->id = new_node.id;     
get_mailbox(new_node.id, cnx_elem->mailbox);
xbt_dynar_push(me->cnx_req_queue, &cnx_elem);

Now, I'd like to search for a given entry in my dynar. Here is something that works:

unsigned int iter = 0;
node_rep_t elem = NULL;
int test = -1;
xbt_dynar_foreach(me->cnx_req_queue, iter, elem) {
	if (!memcmp(elem, cnx_elem, sizeof(*cnx_elem))) {
		if (test == -1) {
			test = iter;

But here is something that doesn't work:

int test = xbt_dynar_search_or_negative(me->cnx_req_queue, &cnx_elem);

This always returns -1 and I really can't understand why, since I thought that these two functions were equivalent.
Can you help me please ?

Thanks a lot.

Best regards,


More information about the Simgrid-user mailing list