How does array_needsize macro work?

Jie Liu ljie314 at
Wed May 6 18:45:14 CEST 2015

When I'm reading the code of libev, I find this definition of "array_needsize":
#define array_needsize(type,base,cur,cnt,init)            \
  if (expect_false ((cnt) > (cur)))                \
    {                                \
      int ecb_unused ocur_ = (cur);                    \
      (base) = (type *)array_realloc                \
         (sizeof (type), (base), &(cur), (cnt));        \
      init ((base) + (ocur_), (cur) - ocur_);            \
According to the comments, memories are allocated in chunks of "MALLOC_ROUND". It is possible that the size needed is larger than "MALLOC_ROUND". In this case, the "array_needsize" may not allocate enough memories because it is using "if" instead of "while". I though there would be a "while" loop but I didn't find it. The library is proved by many projects, so I must miss something here. Could anyone point out how it works?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the libev mailing list