On Wed, 2007-11-28 at 19:07 -0500, Dave Robillard wrote:
Same with LV2 ports; works perfectly for port types. Problem is,
sticking a URI in each /event/ is far too bloated/slow.
I am coming horribly late to this discussion, so I might be being thick,
but what happens if each event contains a pointer to a C style string
being the URI... Bloated and slow right?
Now here is the trick, we convert that to a unique identifier at run
time by registering each unique event URI as a string in some data
structure (Map, linked list of parameters, whatever), then at event
creation time we set the pointer to point to our single common instance
of the URI. Now all events of a given type have the same value stored in
that pointer which will serve as a unique ID for this event for run of
the programme. If saving event data to disk, we just replace the pointer
with the string it pointed to.
struct event_t {
char * uri;
size_t data_length;
char data[1]
};
On loading a set of events build a list of every unique uri and patch
each events uri pointer to point to it.
struct known_events {
char *uri;
int (*handler)(struct event_t * ev, void *param);
struct known_events *next;
}
Or something like that.
Now using the fact that the address of a struct is the address of the
first element of the struct, running an event is simply
((struct known_events *) event.uri)->handler (event,whatever);
Or something like that, I didn't try to compile it.
If we wish to check if two events are of the same type then
if ((char*) event1.uri == (char*) event2.uri){
is sufficient and is a single 32 or 64 bit integer comparison.
Just a thought.
Regards, Dan.