Skip to content

Commit

Permalink
new(plugin): add EventBatch.reserve
Browse files Browse the repository at this point in the history
This lets the plugin inform the SDK about how many events
it's planning to emit in the current batch and hopefuly minimize
memory copies when growing the `pointers` vector

Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
  • Loading branch information
gnosek authored and poiana committed Oct 18, 2024
1 parent 10aadf2 commit 9af8a52
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions falco_plugin/src/plugin/source/event_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ impl EventBatch<'_> {
Ok(())
}

/// # Reserve space for a specific number of events
///
/// If your plugin knows it's going to generate a specific number of events
/// in a particular batch, it can call this method to preallocate some space
/// and save a bit of overhead.
///
/// The passed value is only a hint, the actual batch can be smaller or larger
/// than the reserved size, but that mostly defeats the purpose of reserving
/// space
pub fn reserve(&mut self, num_events: usize) {
self.pointers.reserve(num_events);
}

pub(in crate::plugin::source) fn get_events(&self) -> &[*const u8] {
self.pointers.as_slice()
}
Expand Down

0 comments on commit 9af8a52

Please sign in to comment.