Re: Avoid memory allocations on matrix resize.

Joaquim Duran <[email protected]>
Newsgroups gmane.comp.lib.boost.ublas
Message-ID <CANdawSHcha0i6F1WHXG+qO-UPV=Z=nAb4sopPKhCJVOkUB43+g@mail.gmail.com>
Already done in storage. Sorry.



2013/10/12 Joaquim Duran <[email protected]>

> 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
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.