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 6219727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:50:07+00:00 2026-05-24T07:50:07+00:00

I have some large arrays of 2D data elements. A and B aren’t equally

  • 0

I have some large arrays of 2D data elements. A and B aren’t equally sized dimensions.

A) is between 5 and 20

B) is between 1000 and 100000

The initialization time is no problem as its only going to be lookup tables for realtime application, so performance on indexing elements from knowing value A and B is crucial. The data stored is currently a single byte-value.

I was thinking around these solutions:

byte[A][B] datalist1a;

or

byte[B][A] datalist2a;

or

byte[A,B] datalist1b;

or

byte[B,A] datalist2b;

or perhaps loosing the multidimension as I know the fixed size and just multiply the to values before looking it up.

byte[A*Bmax + B] datalist3;

or

byte[B*Amax + A] datalist4;

What I need is to know, what datatype/array structure to use for most efficient lookup in C# when I have this setup.

Edit 1
the first two solutions were supposed to be multidimensional, not multi arrays.

Edit 2
All data in the smallest dimension is read at each lookup, but the large one is only used for indexing once at a time.

So its something like – Grab all A’s from sample B.

  • 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-05-24T07:50:08+00:00Added an answer on May 24, 2026 at 7:50 am

    I’d bet on the jagged arrays, unless the Amax or Bmax are a power of 2.

    I’d say so, because a jagged array needs two indexed accesses, thus very fast. The other forms implies a multiplication, either implicit or explicit. Unless that multiplication is a simple shift, I think could be a bit heavier than a couple of indexed accesses.

    EDIT: Here is the small program used for the test:

    class Program
    {
        private static int A = 10;
        private static int B = 100;
    
        private static byte[] _linear;
        private static byte[,] _square;
        private static byte[][] _jagged;
    
    
    
        unsafe static void Main(string[] args)
        {
            //init arrays
            _linear = new byte[A * B];
            _square = new byte[A, B];
            _jagged = new byte[A][];
            for (int i = 0; i < A; i++)
                _jagged[i] = new byte[B];
    
            //set-up the params
            var sw = new Stopwatch();
            byte b;
            const int N = 100000;
    
            //one-dim array (buffer)
            sw.Restart();
            for (int i = 0; i < N; i++)
            {
                for (int r = 0; r < A; r++)
                {
                    for (int c = 0; c < B; c++)
                    {
                        b = _linear[r * B + c];
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("linear={0}", sw.ElapsedMilliseconds);
    
            //two-dim array
            sw.Restart();
            for (int i = 0; i < N; i++)
            {
                for (int r = 0; r < A; r++)
                {
                    for (int c = 0; c < B; c++)
                    {
                        b = _square[r, c];
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("square={0}", sw.ElapsedMilliseconds);
    
            //jagged array
            sw.Restart();
            for (int i = 0; i < N; i++)
            {
                for (int r = 0; r < A; r++)
                {
                    for (int c = 0; c < B; c++)
                    {
                        b = _jagged[r][c];
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("jagged={0}", sw.ElapsedMilliseconds);
    
            //one-dim array within unsafe access (and context)
            sw.Restart();
            for (int i = 0; i < N; i++)
            {
                for (int r = 0; r < A; r++)
                {
                    fixed (byte* offset = &_linear[r * B])
                    {
                        for (int c = 0; c < B; c++)
                        {
                            b = *(byte*)(offset + c);
                        }
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("unsafe={0}", sw.ElapsedMilliseconds);
    
            Console.Write("Press any key...");
            Console.ReadKey();
            Console.WriteLine();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some very large data files (5 gig to 1TB) where we need
I have a large data.frame displaying some weird properties when plotted. I'd like to
I'm trying to optimize some code where I have a large number of arrays
I have a large array of vertices, some of them are edges, some are
I'm looking at building a Rails application which will have some pretty large tables
I have an automated test running on my program that generates some large MPG
I have an application on the Compact Framework that has some large embedded resources
I have been starting to write some reasonably large and or confusing MySQL queries
We're in the initial stages of a large project, and have decided that some
I have a large project but I need only some folders in my svn

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.