Boost logo

Ublas :

Subject: Re: [ublas] Avoid memory allocations on matrix resize.
From: Joaquim Duran (jduran.gm_at_[hidden])
Date: 2013-10-12 12:54:26


Already done in storage. Sorry.

2013/10/12 Joaquim Duran <jduran.gm_at_[hidden]>

> Dear all,
>
> When a matrix is resized, always, new memory is allocated, even when the
> resize operation doesn't changes the current size of the matrix. I propose
> to add a check in resize to ignore the operation if no resize is done.
> Something like:
>
> BOOST_UBLAS_INLINE
> void resize (size_type size1, size_type size2, bool preserve = true) {
> + if ((size1 == size1_) && (size2 == size2_)) {
> + return;
> +}
>
> if (preserve) {
> self_type temporary (size1, size2);
> detail::matrix_resize_preserve<layout_type> (*this, temporary);
> }
> else {
> data ().resize (layout_type::storage_size (size1, size2));
> size1_ = size1;
> size2_ = size2;
> }
> }
>
> Thanks and Best Regards,
> Joaquim Duran
>
>