|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
MTL: creation of matrix elementsThank you for your insight, Peter.
By looking at your code (contiguous_memory_block.hpp, generic_array<..>::alloc(..)) I've noticed, that you don't initialize matrix elements on allocation. That method seems to be called from some methods of dense2D, such as resize(..). If that is the case, the library won't work with any class, that has a non-trivial default constructor. Is this by design? In order to cover classes with non-trivial default constructors (STL has no problem with this), you might want to invoke in-place operator new on the newly allocated memory in generic_array<..>::alloc(..) and perhaps other places as well. If the default constructor of the element type is trivial, the compiler will probably optimize this call out and you won't loose in performance.
Michael. ----- Original Message ----- -- Want an e-mail address like mine?
Get a free e-mail account today at www.mail.com! _______________________________________________ This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/ |
|
|
Re: MTL: creation of matrix elementsOn Sunday 23 December 2007, Michael Smolsky wrote:
> Thank you for your insight, Peter. > > By looking at your code (contiguous_memory_block.hpp, > generic_array<..>::alloc(..)) I've noticed, that you don't initialize > matrix elements on allocation. That method seems to be called from some > methods of dense2D, such as resize(..). If that is the case, the library > won't work with any class, that has a non-trivial default constructor. > If you look at the current boost::ublas, you'll find e.g.: unbounded_array (size_type size, const ALLOC &a = ALLOC()): alloc_(a), size_ (size) { if (size_) { data_ = alloc_.allocate (size_); if (! detail::has_trivial_constructor<T>::value) { for (pointer d = data_; d != data_ + size_; ++d) alloc_.construct(d, value_type()); also: namespace detail { // specialisation which define whether a type has a trivial constructor // or not. This is used by array types. template<typename T> struct has_trivial_constructor : public boost::has_trivial_constructor<T> {}; template<typename T> struct has_trivial_destructor : public boost::has_trivial_destructor<T> {}; template<typename FLT> struct has_trivial_constructor<std::complex<FLT> > : public boost::true_type {}; template<typename FLT> struct has_trivial_destructor<std::complex<FLT> > : public boost::true_type {}; } I believe this is a good approach _______________________________________________ This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/ |
| Free embeddable forum powered by Nabble | Forum Help |