Skip to content

Commit cb278e1

Browse files
noc0lourmarcusmueller
authored andcommittedFeb 17, 2018
blocks: reserve memory in vector_sink constructor
1 parent caa4e5d commit cb278e1

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed
 

‎gr-blocks/grc/blocks_vector_sink_x.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<name>Vector Sink</name>
99
<key>blocks_vector_sink_x</key>
1010
<import>from gnuradio import blocks</import>
11-
<make>blocks.vector_sink_$(type.fcn)($vlen)</make>
11+
<make>blocks.vector_sink_$(type.fcn)($vlen, $reserve_items)</make>
1212
<param>
1313
<name>Input Type</name>
1414
<key>type</key>
@@ -45,6 +45,13 @@
4545
<value>1</value>
4646
<type>int</type>
4747
</param>
48+
<param>
49+
<name>Reserve memory for items</name>
50+
<key>reserve_items</key>
51+
<value>1024</value>
52+
<type>int</type>
53+
<hide>part</hide>
54+
</param>
4855
<check>$vlen &gt; 0</check>
4956
<sink>
5057
<name>in</name>

‎gr-blocks/include/gnuradio/blocks/vector_sink_X.h.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- c++ -*- */
22
/*
3-
* Copyright 2004,2008,2009,2013 Free Software Foundation, Inc.
3+
* Copyright 2004,2008,2009,2013,2018 Free Software Foundation, Inc.
44
*
55
* This file is part of GNU Radio
66
*
@@ -41,7 +41,7 @@ namespace gr {
4141
// gr::blocks::@NAME@::sptr
4242
typedef boost::shared_ptr<@NAME@> sptr;
4343

44-
static sptr make(int vlen = 1);
44+
static sptr make(const int vlen = 1, const int reserve_items = 1024);
4545

4646
//! Clear the data and tags containers.
4747
virtual void reset() = 0;

‎gr-blocks/lib/vector_sink_X_impl.cc.t

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- c++ -*- */
22
/*
3-
* Copyright 2004,2008,2010,2013,2017 Free Software Foundation, Inc.
3+
* Copyright 2004,2008,2010,2013,2017-2018 Free Software Foundation, Inc.
44
*
55
* This file is part of GNU Radio
66
*
@@ -36,18 +36,20 @@ namespace gr {
3636
namespace blocks {
3737

3838
@NAME@::sptr
39-
@BASE_NAME@::make(int vlen)
39+
@BASE_NAME@::make(const int vlen, const int reserve_items)
4040
{
4141
return gnuradio::get_initial_sptr
42-
(new @NAME_IMPL@(vlen));
42+
(new @NAME_IMPL@(vlen, reserve_items));
4343
}
4444

45-
@NAME_IMPL@::@NAME_IMPL@(int vlen)
45+
@NAME_IMPL@::@NAME_IMPL@(const int vlen, const int reserve_items)
4646
: sync_block("@NAME@",
4747
io_signature::make(1, 1, sizeof(@TYPE@) * vlen),
4848
io_signature::make(0, 0, 0)),
4949
d_vlen(vlen)
5050
{
51+
gr::thread::scoped_lock guard(d_data_mutex);
52+
d_data.reserve(d_vlen * reserve_items);
5153
}
5254

5355
@NAME_IMPL@::~@NAME_IMPL@()

‎gr-blocks/lib/vector_sink_X_impl.h.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- c++ -*- */
22
/*
3-
* Copyright 2004,2008,2009,2013,2017 Free Software Foundation, Inc.
3+
* Copyright 2004,2008,2009,2013,2017-2018 Free Software Foundation, Inc.
44
*
55
* This file is part of GNU Radio
66
*
@@ -40,7 +40,7 @@ namespace gr {
4040
int d_vlen;
4141

4242
public:
43-
@NAME_IMPL@(int vlen);
43+
@NAME_IMPL@(const int vlen, const int reserve_items);
4444
~@NAME_IMPL@();
4545

4646
void reset();

0 commit comments

Comments
 (0)
Please sign in to comment.