Forum: GNU Radio Avoid double memory initilization in PMT unified vectors

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A725014f091bcd9e8ff16e9f2a0d7e20?d=identicon&s=25 Stefan Brüns (Guest)
on 2008-10-07 19:45
(Received via mailing list)
Hi,

in PMT, there is code like:

pmt_u8vector::pmt_u8vector(size_t k, uint8_t fill)
  : d_v(k)
{
  for (size_t i = 0; i < k; i++)
    d_v[i] = fill;
}

As std::vector initializes the memory by itself when called with an size
argument in the constructor, the memory is initialized twice.

A faster version with the same result is:

pmt_u8vector::pmt_u8vector(size_t k, uint8_t fill)
  : d_v(k, fill)
{}

Same is true for the other data types.

Another question:
Why are the classes for the different types written "by hand", and not
using
templates, eg:

template <typename T>
class pmt_uniform_vector
{
  ...
}
typedef pmt_uniform_vector< uint8_t > pmt_u8vector;

Stefan

--
Stefan Brüns  /  Bergstraße 21  /  52062 Aachen
mailto:lurch at gmx.li  http://www.kawo1.rwth-aachen.de/~lurchi/
   phone: +49 241 53809034     mobile: +49 151 50412019
745d8202ef5a58c1058d0e5395a78f9c?d=identicon&s=25 Eric Blossom (Guest)
on 2008-10-07 21:24
(Received via mailing list)
On Tue, Oct 07, 2008 at 07:26:08PM +0200, Stefan Brüns wrote:
>
> As std::vector initializes the memory by itself when called with an size
> argument in the constructor, the memory is initialized twice.
>
> A faster version with the same result is:
>
> pmt_u8vector::pmt_u8vector(size_t k, uint8_t fill)
>   : d_v(k, fill)
> {}

Thanks.  I'll fix.


> }
> typedef pmt_uniform_vector< uint8_t > pmt_u8vector;
>
> Stefan

My goal was to keep the interface completely opaque.  It's likely that
the underlying implementation will be completely rewritten at some
point.  Although we're currently using a C++ style implementation,
it's quite possible that we'll move to a more lisp-style
implementation with type info stored in the low pointer bits, GC
instead of reference counting, etc.

Using templates in the .cc files to reduce replicated code would be a
good idea with the current implementation.

Eric
This topic is locked and can not be replied to.