Work function template for vector I/O

I’m sure this must exist somewhere but I’ve been unable to find it among
the tutorials and mailing lists.

I’ve got the basics of writing blocks down. I’ve successfully created a
C++
block with float input and output streams, and gotten it to load into
GRC.

Now I’d like to do something more interesting with vector I/O, probably
complex vectors. It’s my understanding that each input or output item
can
be an entire vector, correct? and that consuming or generating
one
item means consuming or generating that entire array?

Does anyone have a source example? I’m uncertain about things like what
the
cast of input_items and output_items should look like. Also the memory
allocation. Do I create a new vector for each output item and trust that
GRC will destroy it somewhere downstream? I’m talking about vectors that
may potentially contain megabytes, so I want to make sure I do the
memory
management right.

    Randy

On 11.02.2014 09:57, Randall Poe wrote:

the cast of input_items and output_items should look like. Also the
memory allocation. Do I create a new vector for each output item and
trust that GRC will destroy it somewhere downstream? I’m talking about
vectors that may potentially contain megabytes, so I want to make sure I
do the memory management right.

Randall,

a couple of things:

  • There’s tons of examples, check out any block with a _vcc suffix.
    Short answer, you just set the item size (e.g. sizeof(gr_complex) *
    vlen).
  • Cast: const gr_complex *input_items = (const gr_complex *)
    input_items[0];
  • This will not generate a std::vector, but a regular C-style array.
    You don’t need to destroy it, the buffers get allocated automatically.
  • You don’t have unlimited space in buffers between blocks. If you’re
    streaming massive amounts, you might want to use tags to declare item
    boundaries.

MB

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs