cristicbz/scid — Issue #77: Heap allocations when copying non-view storages
Author: cristicbz
Created: 2011-12-19 17:37:43+00:00
State: open

Because of the way views are implemented, an extra ref-counter is needed to store the number of views pointing to the same matrix **object**, in addition to the counter counting the number of objects pointing to the same **memory** used for copy-on-write.

Unfortunately this means whenever a non-view storage is copied, it creates a new RefCounted pointing to a copy of the underlying container. Since RefCounted heap-allocates memory on construction, it means something as innocuous as a matrix-matrix copy, while not copying the underlying data, still performs a heap allocation.

With the current design, the only way to alleviate this would be to provide a custom RefCounted type which uses a free list custom allocator.

Note:This would not help with the extra pointer indirection, but I've no idea how to remove that; however, ideally, performance-critical operations will be done using matrix ops, thus avoiding many quick-succession data accesses. When this cannot be avoided, one always has the option of using the .data & .cdata properties directly, with the proper precaution.