ISO: A good example of associating custom data with a watcher (timer, etc.)

Rodrigo Campos rodrigo at
Tue Dec 1 00:52:54 CET 2015

On Mon, Nov 30, 2015 at 11:32:48PM +0000, Chris Galas wrote:
> I'm looking for a good 'c' example of associating custom data with a watcher, say an ev_timer.
> I subclass the ev_timer struct and then add my own data to the end. What will insure the 'base' come first in memory versus my own data?
> typedef struct ev_mytimer
> {
>   struct ev_timer base;
>   void* myData;
> } ev_mytimer;

Not sure if I misunderstand your question, but what assures that in mem "first" is
base and then "myData" is the order you declare them in the struct. The order in
C structs matters, and implies the order in memory.

Note, however, that padding might be used between "base" and "myData". But the
order will be kept. But this just C and not related to libev, if I understand
the question correctly :)


More information about the libev mailing list