title: libevent API: understanding the pointer parameters or return values
body: <p>for the following libevent API:</p>
  
  <pre><code>void event_set(struct event *ev, int fd, short event, void (*cb)(int, short, void *), void *arg)
  
  event_add(struct event *ev, const struct timeval *timeout); 
  
  struct event* event_new (struct event_base *, evutil_socket_t, short, event_callback_fn, void)   
  </code></pre>
  
  <p>I want to know:</p>
  
  <p>1) for pointer parameter <code>ev</code> in the second function <code>event_add</code>, the function <code>event_add</code> makes  a local copy of the ev structure or not? </p>
  
  <p>for example, if I do something like: </p>
  
  <pre><code>  code snippet 1:
  
       struct event ev;
       event_set(&amp;ev, ..para list 1...);    // event 1 
       event_add(&amp;ev, ...);
       event_set(&amp;ev, ..para list 2...);    // event 2
       event_add(&amp;ev, ...);
  </code></pre>
  
  <p>event 1 is different from event 2 because parameter list 1 is different from parameter list 2. if event_add makes a local copy, then it is no problem, but if event_add doesn't make a local copy, then these two <code>event_add</code> actually add only event 2?</p>
  
  <p>besides, if I have a main function:</p>
  
  <pre><code>   void func(){
       struct event ev;
       event_set(&amp;ev, ...);
       event_add(&amp;ev, ...)
     }
  
     int main(){
        func();
        event_base_dispatch(base);
     }
  </code></pre>
  
  <p>after func() is called, the execution returns to main(). since <code>ev</code> is a local variable inside func(). if event_add(&amp;ev,...) doesn't make a local copy, then <code>ev</code> is nowhere to find and there will be a problem.
  so can I call event_add() on a local event structure?  </p>
  
  <p>I want to add many timer events(use something like evtimer_set) from time to time, and the adding happens in some callback functions. so I can't define global variabbles for the timeout events in advance, if event_add() can't be called on local variables, are there any solutions for this?  </p>
  
  <p>2) <code>event_new</code> returns a structure pointer, I want to know where is the structure, it is in a stack/heap memory or static memory?</p>
  
  <p><strong>MY special case:</strong>:</p>
  
  <pre><code>        in the main.c
  
                 int main(){
                      struct event_base *base;
                      struct event pcap_ev;
                      .....                     // here I get a file descriptor pcapfd
                      event_set(&amp;pcap_ev, pcapfd, EV_READ|EV_PERSIST, on_capture, pcap_handle);
                      event_base_set(base, &amp;pcap_ev);
                      event_add(&amp;pcap_ev, NULL);
                      .....
                      event_base_dispatch(base);
                 }
  
           on_capture callback function:
                  void *on_capture(int pcapfd, short op, void *arg)
                  {
                   pcap_t *handle;
                   handle = (pcap_t *)arg;
                   fqueue_t* pkt_queue;
  
                   pkt_queue = init_fqueue();
                   pcap_dispatch(handle, -1, collect_pkt, pkt_queue);  // this function put all the cached packets into pkt_queue
                   process_pcap(pkt_queue);
                  }
  
            the sub-routine process_pcap():
  
                  void process_pcap(pkt_queue);{
                        for (pkt in pkt_queue){      // here is pseudo code
                             insert(table, pkt);     // here insert the pkt into a certain table 
                             struct event pkt_ev;
                             evtimer_set(&amp;pkt_ev, timer_cb, NULL);  // I want to call timer_cb after timeout
                             event_base_set(base, &amp;pkt_ev);
                             event_add(&amp;pkt_ev, timeout);                     
                        }
                  }
  
           the callback function timer_cb():
  
                  timer_cb(...){
                       if(...)  delete(table, pkt);
                       .......
                  }
  </code></pre>
  
  <p>I'm just afraid <code>timer_cb()</code> won't be called because <code>pkt_ev</code> is a local variable.</p>