[zeromq-dev] zhashx_t observation

Juergen Gnoss jgnoss at hotmail.com
Mon Oct 23 12:51:16 CEST 2017



I use czmq from master pulled and built a few days ago.


zhashx_t is meant as a hash that can handle other objects than strings.

That's what I understand and that's how I used it in some projects before.

(both, objects and keys where other than simple strings)


Now I did use zframe_t as keys and (char *) as items and setup zhashx like so:


assuming that my items (constant strings) are handled out of the box I just

gave comparator, duplicator and destructor to the key, which in my case is

another object than a string.



first defining the comparator


```c

static int s_scompfn(zframe_t *f1, zframe_t *f2){
    if (zframe_eq(f1, f2)) {
        return 0;
    }
    return 1;
}


```

then


```c

zhashx_t *deviceComID_List = zhashx_new ();


zhashx_set_key_destructor (deviceComID_List, (zhashx_destructor_fn *) zframe_destroy);
zhashx_set_key_duplicator (deviceComID_List, (zhashx_duplicator_fn *) zframe_dup);
zhashx_set_key_comparator(deviceComID_List, (zhashx_comparator_fn *) s_scompfn);

```

some code to use that hash is


```c


    char *item = (char *)zhashx_lookup(deviceList, cid_frame);
    if (item == NULL) {
        zhashx_insert(deviceList, cid_frame, "");
    } else {
        zhashx_delete (deviceList, cid_frame);
    }


```


Ending up that the program eats up all my memory as seen in

https://pastebin.com/JCdPGHME

(that's the valgrind massif output)



Is it, because my (item) strings are empty at that moment?


If I give constructor and duplicator as well for the items (strings) to zhashx,

it works as expected.


https://pastebin.com/mCvtKp6L



I didn't get it from Documentation, that all that duplicators and

destructors are obligatory to set.


Am I the only one stumbling into that?


Ju







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20171023/3afcf28c/attachment.htm>


More information about the zeromq-dev mailing list