Boost logo

Ublas :

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

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:

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