# PROBLEM: Understanding gr\_block's implementation

**URL:** <https://www.ruby-forum.com/t/problem-understanding-gr-blocks-implementation/125209>\
**Category:** GNU Radio\
**Created:** [January 7, 2008, 3:29am UTC](https://www.ruby-forum.com/t/problem-understanding-gr-blocks-implementation/125209 "2008-01-07T03:29:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonas\_Gacrama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@Jonas\_Gacrama](https://www.ruby-forum.com/u/Jonas_Gacrama)\
**Post date:** [January 7, 2008, 3:29am UTC](https://www.ruby-forum.com/t/problem-understanding-gr-blocks-implementation/125209/1 "2008-01-07T03:29:21Z")

</div>

These are some of the input parameters of gr\_block::general\_work() :

input\_items vector of pointers to the input items, one entry per input  
stream  
output\_items vector of pointers to the output items, one entry per  
output stream

Am I correct in understanding that the input\_items CAN point to a  
vector type of inputs? I plan to implement two input channels  
of vector type. Therefore I plan to pass TWO POINTERS of  
vector type as “input\_items” to general\_work.

Note that the discussion on this website:  
“[http://www.gnu.org/software/gnuradio/doc/howto-write-a-block.html](http://www.gnu.org/software/gnuradio/doc/howto-write-a-block.html)”  
only used one  
“channel” of inputs since it only took values from a single stream. I  
plan to take TWO CHANNELS of inputs wherein each channel contains  
10000 inputs.

Thanks!

---

<div class="post-metadata">

**Author:** ![Jonas\_Gacrama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@Jonas\_Gacrama](https://www.ruby-forum.com/u/Jonas_Gacrama)\
**Post date:** [January 7, 2008, 4:42am UTC](https://www.ruby-forum.com/t/problem-understanding-gr-blocks-implementation/125209/2 "2008-01-07T04:42:01Z")

</div>

On Mon, Jan 07, 2008 at 10:28:39AM +0800, Jonas Gacrama wrote:

> These are some of the input parameters of gr\_block::general\_work() :
> 
> input\_items vector of pointers to the input items, one entry per input stream  
> output\_items vector of pointers to the output items, one entry per  
> output stream
> 
> Am I correct in understanding that the input\_items CAN point to a  
> vector type of inputs?

No, the data items must be “plain-old-data”…  
Something that can be copied safely with memcpy.

> I plan to implement two input channels  
> of vector type. Therefore I plan to pass TWO POINTERS of  
> vector type as “input\_items” to general\_work.

Do you mean that each “item” is conceptually a vector of 10,000  
floats? And that your block operates on two input streams, each of  
which contains “items” that are vectors of 10,000 floats?

If so, you input signature should be:

gr\_make\_io\_signature(2, 2, 10000 \* sizeof(float))

Unless your block has a time varying i/o rate between input and  
output, I’d recommend that you derive your class from gr\_sync\_block  
instead of gr\_block. It’s easier that way.

> Note that the discussion on this website:  
> “[GNU Radio - Free & Open Source Software Radio](http://www.gnu.org/software/gnuradio/doc/howto-write-a-block.html)”  
> only used one  
> “channel” of inputs since it only took values from a single stream. I  
> plan to take TWO CHANNELS of inputs wherein each channel contains  
> 10000 inputs.

One of the joys of Free Software is that the code is available to  
inspect. There are 100’s of blocks to look at, and at least 1/2 of  
them take more than a single input.

In particular, you may want to look at the code for  
gr\_add\_vff.{h,cc} which adds streams of vectors of floats together and  
gr\_add\_ff.{h,cc} which adds streams of floats together.

Eric

---

<div class="post-metadata">

**Author:** ![Jonas\_Gacrama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@Jonas\_Gacrama](https://www.ruby-forum.com/u/Jonas_Gacrama)\
**Post date:** [January 7, 2008, 5:21am UTC](https://www.ruby-forum.com/t/problem-understanding-gr-blocks-implementation/125209/3 "2008-01-07T05:21:45Z")

</div>

Yes, each “item” is supposed to be a vector of 10000 floats; and yes,  
each input stream contains 10000 floats. I chose a vector type for  
flexibility but I could always go back to turning it into a “plain old  
data”.

In that case, could I pass a multidimensional array as an input  
argument to general\_work? For example, I pass array\_name[2][10000]  
where the main index [2] in this case, represents 2 inputs streams?

I don’t really intend to vary the input and output rates, but thanks  
for the suggestion on using gr\_sync\_block! I’ll try it too.

As a side note to , I already created functions that do just  
that. It’s already incorporated into the main signal processing block  
that I am creating. But thanks for the suggestion! I’ll see if I could  
use it.

=)
