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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:45:37+00:00 2026-06-11T03:45:37+00:00

in my application I have a very large array of bytes, its a flattened

  • 0

in my application I have a very large array of bytes, its a flattened 3 dimensional array, we populate the array using 3 nested for loops (x, y, z) and then we get the values we want by using a little bit of math, most specifically:

To get an index in the array:

return x + z*SizeX + y*SizeX*SizeZ;

and to return the x/y/z coordinates, given an index:

int index = pos;
var y = (ushort) (pos/SizeX/SizeZ);
pos -= y*SizeX*SizeZ;
var z = (ushort) (pos/SizeX);
pos -= z*SizeX;
var x = (ushort) pos;

return new BlockPos(x, y, z, index, this);

First off, I would imagine the second one can be made more efficient, i just don’t know how to do it, any help there would be appreciated 😛

My main quesion is, would it be faster for me to make a lookup table for the y and x values (populating when the class is loaded) or is it faster to just leave the multiplication in there?

edit
This math is called a LOT in some cases, so if it would be faster, even for a longer startup it would make a differance better.

  • 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-11T03:45:39+00:00Added an answer on June 11, 2026 at 3:45 am

    In most languages and architectures, multiplication will become one (or a few) machine instructions. Whilst those instructions may be relatively expensive, they should still be cheaper that performing a lookup operation – and a lookup operation may very well require a multiplication anyway.

    E.g. “locate the 4th element of the array” will be

    <array base address> + (3 * <array element size>)
    

    The only optimization I’d recommend given your pseudo code is to perform the “constant” operations (e.g. SizeX*SizeZ) once, and store those results.

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

Sidebar

Related Questions

I have a very large ASP.NET application in C#. The issue is simple yet
I have a very large set of permissions in my application that I represent
I have a problem with a memory leak in a very large ASP.NET application.
I have an algorithm which currently allocates a very large array of doubles, which
I have a very large C++ server application on Windows (Win7). It compiles fine
I have a very large, complex (million+ LOC) Windows application written in C++. We
I have an application which predictably generates out-of-memory errors on very, very (very) large
I'm working on a web application where we have a very large image (4000
We have a very large JavaScript application, where after many months of coding there
I have some very large processing being done in a php application. I'd like

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.