diff options
author | Marcus Müller <marcus.mueller@ettus.com> | 2018-02-17 22:59:38 +0100 |
---|---|---|
committer | Marcus Müller <marcus.mueller@ettus.com> | 2018-02-17 22:59:38 +0100 |
commit | b52726077244d2b8439c663144e5f013fa3d8557 (patch) | |
tree | 4d57288bd1c7817a6814e0e201aa8b22f225bca7 | |
parent | caa4e5d34daf8e27c6ae7ddf982ae25113a934e3 (diff) | |
parent | c60fdbb75c7db6d000ef13dab66c393501840e21 (diff) |
Merge branch 'noc0lour-add_vector_reserve'
This gives gr::blocks::vector_sink_X the ability to reserve a
user-specified amount of items worth of memory at initialization.
Benefit is that this can avoid reallocations (and hence, memory moves!),
especially when the amount of items to be stored is known beforehand.
-rw-r--r-- | gr-blocks/grc/blocks_vector_sink_x.xml | 9 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/vector_sink_X.h.t | 13 | ||||
-rw-r--r-- | gr-blocks/lib/vector_sink_X_impl.cc.t | 10 | ||||
-rw-r--r-- | gr-blocks/lib/vector_sink_X_impl.h.t | 4 |
4 files changed, 27 insertions, 9 deletions
diff --git a/gr-blocks/grc/blocks_vector_sink_x.xml b/gr-blocks/grc/blocks_vector_sink_x.xml index 7f51731975..9c96ffb85a 100644 --- a/gr-blocks/grc/blocks_vector_sink_x.xml +++ b/gr-blocks/grc/blocks_vector_sink_x.xml @@ -8,7 +8,7 @@ <name>Vector Sink</name> <key>blocks_vector_sink_x</key> <import>from gnuradio import blocks</import> - <make>blocks.vector_sink_$(type.fcn)($vlen)</make> + <make>blocks.vector_sink_$(type.fcn)($vlen, $reserve_items)</make> <param> <name>Input Type</name> <key>type</key> @@ -45,6 +45,13 @@ <value>1</value> <type>int</type> </param> + <param> + <name>Reserve memory for items</name> + <key>reserve_items</key> + <value>1024</value> + <type>int</type> + <hide>part</hide> + </param> <check>$vlen > 0</check> <sink> <name>in</name> diff --git a/gr-blocks/include/gnuradio/blocks/vector_sink_X.h.t b/gr-blocks/include/gnuradio/blocks/vector_sink_X.h.t index a4ef38fd04..8d9c757862 100644 --- a/gr-blocks/include/gnuradio/blocks/vector_sink_X.h.t +++ b/gr-blocks/include/gnuradio/blocks/vector_sink_X.h.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008,2009,2013 Free Software Foundation, Inc. + * Copyright 2004,2008,2009,2013,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -41,7 +41,16 @@ namespace gr { // gr::blocks::@NAME@::sptr typedef boost::shared_ptr<@NAME@> sptr; - static sptr make(int vlen = 1); + /*! + * \brief Make a new instance of the vector source, and return a shared pointer to it. + * \param vlen length of vector items + * \param reserve_items reserve space in the internal storage for this many items; + * the internal storage will still grow to accommodate more item + * if necessary, but setting this to a realistic value can avoid + * memory allocations during runtime, especially if you know a + * priori how many items you're going to store. + */ + static sptr make(const int vlen = 1, const int reserve_items = 1024); //! Clear the data and tags containers. virtual void reset() = 0; diff --git a/gr-blocks/lib/vector_sink_X_impl.cc.t b/gr-blocks/lib/vector_sink_X_impl.cc.t index 3155c0cb67..630ddb9165 100644 --- a/gr-blocks/lib/vector_sink_X_impl.cc.t +++ b/gr-blocks/lib/vector_sink_X_impl.cc.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008,2010,2013,2017 Free Software Foundation, Inc. + * Copyright 2004,2008,2010,2013,2017-2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -36,18 +36,20 @@ namespace gr { namespace blocks { @NAME@::sptr - @BASE_NAME@::make(int vlen) + @BASE_NAME@::make(const int vlen, const int reserve_items) { return gnuradio::get_initial_sptr - (new @NAME_IMPL@(vlen)); + (new @NAME_IMPL@(vlen, reserve_items)); } - @NAME_IMPL@::@NAME_IMPL@(int vlen) + @NAME_IMPL@::@NAME_IMPL@(const int vlen, const int reserve_items) : sync_block("@NAME@", io_signature::make(1, 1, sizeof(@TYPE@) * vlen), io_signature::make(0, 0, 0)), d_vlen(vlen) { + gr::thread::scoped_lock guard(d_data_mutex); + d_data.reserve(d_vlen * reserve_items); } @NAME_IMPL@::~@NAME_IMPL@() diff --git a/gr-blocks/lib/vector_sink_X_impl.h.t b/gr-blocks/lib/vector_sink_X_impl.h.t index bf4811dfde..dfcb2ccc04 100644 --- a/gr-blocks/lib/vector_sink_X_impl.h.t +++ b/gr-blocks/lib/vector_sink_X_impl.h.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008,2009,2013,2017 Free Software Foundation, Inc. + * Copyright 2004,2008,2009,2013,2017-2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -40,7 +40,7 @@ namespace gr { int d_vlen; public: - @NAME_IMPL@(int vlen); + @NAME_IMPL@(const int vlen, const int reserve_items); ~@NAME_IMPL@(); void reset(); |