Hi all,

I have a block whose output items are running averages over a long integration 
(for the sake of simplicity say a power spectrum accumulated over millions of 
FFT frames, way too many to hold as one input buffer).

The implementation that fell out naturally is: in general_work(), add the next 
batch of partial contributions directly into output_items[0][n_emitted], return 
0 while the integration is still incomplete, and only return n_emitted > 0 when 
one or more integrations are done. It's pretty tempting to do as this would 
practically avoid an extra memory allocation for an internal buffer and a 
memcpy back to output_items when accumulation is ready.

However, this relies on the assumption that returning 0 leaves the write 
pointer unadvanced, so the next general_work() call sees the same memory at 
output_items[0][n_emitted] and I can keep adding into it. 

As far as I can tell, this works on current GR (no-op when produce_each(0) 
<https://github.com/gnuradio/gnuradio/blob/main/gnuradio-runtime/lib/block_detail.cc#L123-L132>
 -> write pointer not updated), but it’s more like an implementation detail 
rather than it being documented as part of the scheduler API.

Two questions:
1) Is the "accumulate into output_items[0] across calls" pattern supported, or 
am I in undocumented/unidentified scheduler/buffer behavior territory?
2) If it's not supported, is there any reason beyond "no API guarantee”; e.g. 
would it break under certain custom buffers or futuristically GR4?

If the answer is just "use an internal buffer," happy to refactor.

Thanks!
Wael

Reply via email to