August 05, 2009

"Denis" <denis-bz-py@t-online.de> wrote in message news:h5bl90$2nsh$1@digitalmars.com...
> Matt,
>   you're right, it's a trivial specific test, plus I'm missing something:
> how do I use pod_vector with auto_buffer ?

Ah, sorry. I didn't realise this was a source of confusion. pod_vector is implemented in terms of auto_buffer.

> Unfortunately I can't open your attachment, Firefox gets newsgroup.php ?

Ok, will repost as content

Matt


August 05, 2009
Here's the test program I used



#include <stlsoft/containers/pod_vector.hpp>
#include <platformstl/performance/performance_counter.hpp>
#include <vector>
#include <stdio.h>


template <typename V>
int calculate(int n, V* = NULL)
{
  V v;

  int sum = 0;

  while( --n >= 0 )
  {
    v.push_back(n);
    //v.push_back(n);
    sum += v[0] /* + v[1] */;
    //v.pop_back();
    //v.pop_back();
  }

  while(!v.empty())
  {
    v.pop_back();
  }

  return sum;
}


int main( int argc, char* argv[] )
{
  typedef std::vector<int>                    vector_t;
  typedef stlsoft::pod_vector<int>                pod_vector_64_t;
  typedef stlsoft::pod_vector<int, std::allocator<int>, 256>    pod_vector_256_t;
  typedef stlsoft::pod_vector<int, std::allocator<int>, 2048>   pod_vector_2028_t;

  const int REPEATS = 100;

  int ITERATIONS[] = { 10, 100, 1000, 10000 };

  int total = 0;

  platformstl::performance_counter  counter;

  platformstl::performance_counter::interval_type   times[4][STLSOFT_NUM_ELEMENTS(ITERATIONS)];

  int sums[4] = { 0, 0, 0, 0 };

  { for(int WARMUPS = 2; 0 != --WARMUPS; )
  {
    { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(ITERATIONS); ++i)
    {
      int ITERATION = ITERATIONS[i];

      counter.start();
      sums[0] += calculate<vector_t>(ITERATION);
      counter.stop();
      times[0][i] = counter.get_microseconds();

      counter.start();
      sums[1] += calculate<pod_vector_64_t>(ITERATION);
      counter.stop();
      times[1][i] = counter.get_microseconds();

      counter.start();
      sums[2] += calculate<pod_vector_256_t>(ITERATION);
      counter.stop();
      times[2][i] = counter.get_microseconds();

      counter.start();
      sums[3] += calculate<pod_vector_2028_t>(ITERATION);
      counter.stop();
      times[3][i] = counter.get_microseconds();
    }}
  }}

  puts("std::vector:");
  { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(ITERATIONS); ++i)
  {
    printf("\t%d:\t%dus\t(%d)\n", ITERATIONS[i], (int)times[0][i], sums[0]);
  }}

  puts("stlsoft::pod_vector<int> (64):");
  { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(ITERATIONS); ++i)
  {
    printf("\t%d:\t%dus\t(%d)\n", ITERATIONS[i], (int)times[1][i], sums[1]);
  }}

  puts("stlsoft::pod_vector<int> (256):");
  { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(ITERATIONS); ++i)
  {
    printf("\t%d:\t%dus\t(%d)\n", ITERATIONS[i], (int)times[2][i], sums[2]);
  }}

  puts("stlsoft::pod_vector<int> (2048):");
  { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(ITERATIONS); ++i)
  {
    printf("\t%d:\t%dus\t(%d)\n", ITERATIONS[i], (int)times[3][i], sums[3]);
  }}


  return 0;
}


August 05, 2009
It doesn't initialise content, that's right. (Hence, in part, the name pod_vector.)

Actually, I thought it was able to do so on a policy-basis, as can the multidimensional arrays, but I'm wrong. Possibly the simplest
workaround for you at the moment is to derive a class from your intended specialisation and provide a ctor with a call to memset.

class mypv
 : stlsoft::pod_vector<int, std::allocator<int>, 512>
{
public:
  typedef stlsoft::pod_vector<int, std::allocator<int>, 512>  parent_class_type;

public:
  explicit mypv(size_t n)
    : parent_class_type(n)
  {
    memset(&(*this)[0], 0, sizeof(int) * n);
  }

Deriving a non-polymorphic class is something of a design smell, but as long as you don't add member variables (or virtual methods),
you should be ok.

In hindsight, I think that pod_vector not initialising in that ctor is a design flaw, and I'm considering changing it. I will
probably do so for STLSoft 1.10.

Matt


----- Original Message ----- 
From: "Denis" <denis-bz-py@t-online.de>
Newsgroups: c++.stlsoft
Sent: Wednesday, August 05, 2009 8:18 PM
Subject: Re: example of <list> with auto_buffer ?


> Matt, ignore the previous mail on funny sum, dumb of me
>  (vector<int> v( 64 ) inits to 0, pod_vector to what ?)
>   -- d


August 05, 2009
> In hindsight, I think that pod_vector not initialising in that ctor is a design flaw, and I'm considering changing it. I will
> probably do so for STLSoft 1.10.

I've now made this change to the STLSoft 1.10 branch, the latest alpha release of which will made in a few days' time.

Note that I also plan to change the template parameter ordering - to more the allocator type into last place - in the same way as
was done for auto_buffer with STLSoft 1.9. As with auto_buffer, a pod_vector_old template will be added for backwards compatibility.

Cheers

Matt

P.S. May I ask how you came to hear about STLSoft, and whether you're using any other of its facilities?



August 11, 2009
This is now available in STLSoft 1.10 (alpha 12)

Let me know how you go

Matt

"Matthew Wilson" <matthew@hat.stlsoft.dot.org> wrote in message news:h5d0kv$1p20$1@digitalmars.com...
> > In hindsight, I think that pod_vector not initialising in that ctor is a design flaw, and I'm considering changing it. I will
> > probably do so for STLSoft 1.10.
>
> I've now made this change to the STLSoft 1.10 branch, the latest alpha release of which will made in a few days' time.
>
> Note that I also plan to change the template parameter ordering - to more the allocator type into last place - in the same way as
> was done for auto_buffer with STLSoft 1.9. As with auto_buffer, a pod_vector_old template will be added for backwards
compatibility.
>
> Cheers
>
> Matt
>
> P.S. May I ask how you came to hear about STLSoft, and whether you're using any other of its facilities?
>
>
>


1 2
Next ›   Last »