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

  • SEARCH
  • Home
  • 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 8801377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:49:08+00:00 2026-06-14T00:49:08+00:00

I have a few questions about multidimensional arrays. I understand how to allocate memory

  • 0

I have a few questions about multidimensional arrays. I understand how to allocate memory for them, but I don’t see why there are needed (Other than to make things more readable).

The [] operator for the array is overloaded, right? So, why can’t a single block of memory be allocated and access be granted by, 1dArray[i*nInRow][offset]?

Are there further performance gains by using an array in multiple dimensions? Also, when memory is dynamically allocated for a 2d array, are they stored in contiguous locations, or are they scattered around the heap? When the data is requested, can I assume that everything is pulled from memory as a block?

Most of the information that I have seen has just explained syntax. Any answers or suggested reading would be great.

  • 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-14T00:49:09+00:00Added an answer on June 14, 2026 at 12:49 am

    The [] operator for the array is overloaded, right? So, why can’t a single block of memory be allocated and access be granted by, 1dArray[i*nInRow][offset]?

    It can, and in fact I would recommend this in the general case.

    Are there further performance gains by using an array in multiple dimensions?

    Not really. Depending on your layout you could optimize cache hits, but then precisely the same is true with the flattened 1D array. The memory layout between the two is (usually) precisely the same. The only difference is the semantic type of the array and the fact that you now have to implement the 2D element lookup yourself.

    Also, when memory is dynamically allocated for a 2d array, are they stored in contiguous locations, or are they scattered around the heap? When the data is requested, can I assume that everything is pulled from memory as a block?

    Arrays are always contiguous.

    You should be careful though that you’re actually allocating a 2D array. Some people write int** ptr = new int*[2] then allocate each “sub-array” manually and think that they have a 2D array. They do not. They have an array of pointers, and that’s when you get your “scattered” layout. Your 2D array is int (*ptr)[3] = new int[2][3];.

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

Sidebar

Related Questions

I have few questions about Doctrine and MySQL working together. I don't understand it
I have a few questions about getters and setters for arrays. Suppose we have
I have read few questions about parsing string by tags, but I didn't find
I have few questions about the memory usage in ssis package. If i am
I have a few questions about PHP memory usage. I'm going to run some
I have few questions about ssis transction isolation levels. consider a scenario:I have an
I have few questions about using lock to protect my shared data structure. I
I have a few questions about Xcode and interaction with GCC 4.2.1: It doesn't
I have a few questions about this after reading the iPhone documentation on it:
I have a few questions about cross-page posting in ASP.NET: What is cross-page posting

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.