Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:37:49+00:00 2026-06-18T12:37:49+00:00

I would like to typedef a multi-dimensional array using the boost library. The matrix

  • 0

I would like to typedef a multi-dimensional array using the boost library. The matrix is rectangular and the dimension and lengths in each dimension should be fixed within the typedef. In case of a vector this was exactly what is solved by the boost::array template class:

typedef boost::array<int, 3> vec3_t;

For multi-dimensional arrays I could repeat this construction

typedef boost::array<boost::array<int, 2> ,3> mat2x3_t

and it allows me to also initialize my matrix quite nicely (although I’m not sure if this behavior is guaranteed…):

Mat2x3_t m = { 11, 12, 13,
               21, 22, 23};

However, from a performance standpoint I am unsure whether this is to way to go. My understanding of memory management is very limited but the way I imagine this in the computer memory is, that the inner-most array (boost::array<int, 2> in the above example) is guaranteed to allocate a contiguous block of memory, whereas, for the “higher levels” of arrays I’n not sure.

I also looked at the boost::multi_array class, where, to my understanding, the whole matrix will take up a contiguous block of memory and is quite ideal for my “rectangular” matrices that I’m interested in. It further supplies some neat member functions (which are not crucial for my implementation but are a nice addition nonetheless). The deal breaker for this class seems to be, however, that I cannot typedef the length in each dimension but only the number of dimensions.

So my question is: Does the the construction in terms of multiple arrays result in performance issues when I have to iterate through it a lot (~10^7 times)? In my example I used a 2×3 int matrix but my use-case would be a higher-dimensional 64x4x2 matrix with complex numbers. And, is the initialization in terms of the curly braces guaranteed by the implementation?
If there are issues with the arrays, is there a way to typedef a fixed size multi_array? Or are the other alternatives I am missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:37:50+00:00Added an answer on June 18, 2026 at 12:37 pm

    boost::array<T, N> (just like its modern cousin, std::array<T, N>) is defined to have just one data member:

    // public data members
    T elems[N];
    

    which is a contiguous sequence of Ts. If each T is an array in turn, the whole thing is contiguous (technically, there could have been gaps due to padding before or after elems, but leading padding is not allowed in this case, and trailing padding is unrealistic.

    Brace initialization and brace elision are guaranteed, although some compilers like to emit warnings if they think you don’t have enough braces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have an array of function pointers, each pointing to a
I would like to remove some edges from a graph generated using Boost graph
I have recently discovered the excellent library boost::accumulators, and I would like to use
I would like to use a templated typedef in various places, among other things
I have typedef std::string OrderID; I would like to overload the operator ++ for
Would like to know what a programmer should know to become a good at
I would like to use this C function in C#: typedef void (*WRITE_CALLBACK)(int hMountEnv,
I am writing a C wrapper an would like to use a typedef aquivalent
I have a typedef inside a class and I would like to overload the
I have a structure I would like to optimize the footprint of. typedef struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.