How does array_needsize macro work?

Jie Liu ljie314 at yahoo.com
Thu May 7 15:31:29 CEST 2015


Could anyone help me? Any help be much appreciated.
Thanks,Jie
 


     On Thursday, May 7, 2015 12:45 AM, Jie Liu <ljie314 at yahoo.com> wrote:
   

 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?
Thanks,Jie



  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20150507/ade48794/attachment.html>


More information about the libev mailing list