Question about MidiBuffer::getNumEvents


I’m wondering why the MidiBuffer class doesn’t keep a variable around containing the current number of events in the buffer, incrementing/decrementing as events are added or removed so that it’s not necessary to traverse the buffer to find the count.



It’s not a random-access data structure - you need to iterate it to access the items, so it seemed unlikely to me that anyone would ever need a fast size() method, and didn’t seem worth the extra complexity of maintaining a counter. There’s an isEmpty() method for quickly finding out if there’s anything in it.