6.2.1 fastmemops

The fastmemops function informs the LYRIC container classes whether the items can be manipulated using standard optimized memory handling functions such as memcpy, memmove, etc, or if the C++ copy constructors and/or derived equal operator have to be used to perform memory operations.


Synopsis


  template <class TYPE>
  inline bool fastmemops (const TYPE& obj);


Description

The fastmemops function returns true if an object of a given type can be handled using memcpy, memmove, etc functions, and false if not. For example LYRIC container classes will always return false, since their content must be cloned with the equal operator. Per default (i.e: fastmemops(type|class) is not user defined), fastmemops returns false.

Every user defined class can be defined with fastmemops returning either true or false. The end programmer must decide whether an object of a given type or class can support to be manipulated in containers with memcpy, memmove, etc, functions. Containers with items that support fast memory operations will be handled much quicker.


Example


1  #include <lyric/Types.hpp>
2  #include <stdio.h>
3  
4  class MyClass
5  {
6  public:
7    MyClass (uint32 val=0)
8      : val_(val) {};
9    MyClass& operator = (const MyClass& obj)
10      { val_ = obj.val_; return *this; }
11    uint32 val () const
12      { return val_; }
13  protected:
14  private:
15    uint32 val_;
16  };
17  
18  inline bool fastmemops (const MyClass& obj) { return (true); }
19  
20  main ()
21  {
22    MyClass obj;
23    if (fastmemops(obj))
24      printf("MyClass has fast memory operations.\n");
25    else
26      printf("MyClass has slow memory operations.\n");
27  }

Better would be to show timings showing the differences between a class with fastmemops and a class without. But the Timer class must work again.