Skip to main content
QUICK REVIEW

[Paper Review] Runtime-Flexible Multi-dimensional Arrays and Views for C++98 and C++0x

Bjoern Andres, Ullrich Koethe|arXiv (Cornell University)|Aug 17, 2010
Parallel Computing and Optimization TechniquesComputer Science8 references6 citations
TL;DR

This paper presents Marray, a C++98 and C++0x-compatible library for runtime-flexible multi-dimensional arrays and views, enabling dynamic dimensionality through view-based abstraction. It achieves C++-idiomatic performance and usability by leveraging views as first-class abstractions, with C++0x extensions for template aliases, variadic templates, and initializer lists to enhance expressiveness and type safety.

ABSTRACT

Multi-dimensional arrays are among the most fundamental and most useful data structures of all. In C++, excellent template libraries exist for arrays whose dimension is fixed at runtime. Arrays whose dimension can change at runtime have been implemented in C. However, a generic object-oriented C++ implementation of runtime-flexible arrays has so far been missing. In this article, we discuss our new implementation called Marray, a package of class templates that fills this gap. Marray is based on views as an underlying concept. This concept brings some of the flexibility known from script languages such as R and MATLAB to C++. Marray is free both for commercial and non-commercial use and is publicly available from www.andres.sc/marray

Motivation & Objective

  • Address the lack of generic, object-oriented C++ implementations for multi-dimensional arrays whose dimension is not fixed at compile time.
  • Enable runtime flexibility in array dimensions while maintaining high performance and type safety in C++.
  • Bridge the usability gap between C++ template libraries (e.g., Boost, Blitz++) and scripting languages (e.g., R, MATLAB) by introducing view-based abstractions.
  • Support practical use cases involving multi-variate data and functions where array dimensions depend on user input or runtime conditions.
  • Provide backward compatibility with C++98 while integrating modern C++0x features to improve code clarity and safety.

Proposed method

  • Model arrays and views using a mathematical framework based on dimension, shape, strides, and offset (d, s, t, p₀), enabling flexible memory layout interpretation.
  • Implement views as class templates that abstract access to underlying data, allowing sub-arrays and reinterpreted layouts without data copying.
  • Use template specialization and inheritance patterns to support both const and mutable views, with C++0x template aliases to reduce code redundancy.
  • Support type-safe access via variadic templates for operator() with any number of coordinate parameters, improving usability over C++98’s limited function overloads.
  • Integrate C++0x initializer lists to allow direct initialization of shape and size using uniform initialization syntax, improving code clarity.
  • Conditionally enable invariant and argument checks via preprocessor macros (NO_DEBUG, NO_ARG_TEST), allowing performance-critical compilation with assertions removed.

Experimental results

Research questions

  • RQ1How can multi-dimensional arrays with dynamically changing dimensions be implemented efficiently and safely in C++ without relying on compile-time template specialization?
  • RQ2To what extent can view-based abstractions in C++ replicate the flexibility of scripting languages like R and MATLAB while maintaining C++ performance and type safety?
  • RQ3What are the most effective C++0x language features (e.g., template aliases, variadic templates, initializer lists) for improving the expressiveness and maintainability of generic multi-dimensional array libraries?
  • RQ4Can a unified, generic interface for arrays and views be designed that supports both fixed- and runtime-dimensioned data structures in a single library?
  • RQ5How can performance-critical runtime checks be conditionally compiled away in production builds without sacrificing correctness during development?

Key findings

  • Marray successfully implements a generic, object-oriented, and runtime-flexible multi-dimensional array and view system in C++98 and C++0x, filling a long-standing gap in C++ scientific computing libraries.
  • The use of views as the core abstraction allows dynamic dimensionality and sub-array access without runtime overhead, achieving performance comparable to native C++ arrays.
  • C++0x extensions such as template aliases, variadic templates, and initializer lists significantly improve code clarity and type safety, especially for high-dimensional access patterns.
  • The library supports both compile-time and runtime dimensionality through a unified interface, enabling seamless integration with existing C++ codebases.
  • Conditional compilation via NO_DEBUG and NO_ARG_TEST allows removal of runtime checks in production builds, ensuring optimal performance without sacrificing development-time safety.
  • The library is publicly available and open-source, with ongoing work on HDF5 integration and C-compatible array interop, indicating strong potential for adoption in HPC and scientific computing.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.