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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:14:34+00:00 2026-06-15T16:14:34+00:00

I would like to know how (if it is possible) could I program a

  • 0

I would like to know how (if it is possible) could I program a Java class using a data layout Array of Class, for example:

public class X{

     double a;
     double b;
     double c;
}

public X array_of_x[SIZE] = new X [SIZE];

but internally the data would be store as a layout of Class of Arrays like this:

 public class X{

     double a[] = new double [SIZE];
     double b[] = new double [SIZE];
     double c[] = new double [SIZE];
}

public X class_x = new X();

My objective is that the programmer could programed in a more intuitive style like the first one, but internal I would do transformations so the data could be continuous in memory, and I would achieve more performance.

Is there any way of doing this so it could accept any class with the first type of struct and be able to convert it to the second approach? (or is any tool that is able to do this type of transformation).

  • 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-15T16:14:35+00:00Added an answer on June 15, 2026 at 4:14 pm

    Let’s create an interface that exhibits the first layout for usage, and an implementation for that interface that uses the second layout internally. (Access modifiers stripped from the code.)

    interface X {
        double getA();
        double getB();
        double getC();
    };
    
    interface ArrayOfX {
        X get(int index);
    };
    
    class ContiguousArrayOfX implements ArrayOfX {
        class ContiguousX implements X {
            int index;
            ContiguousX(int index) {
                this.index = index; }
            double getA() { return a[index]; }
            double getB() { return b[index]; }
            double getC() { return c[index]; }
        }
    
        X get(int index) {
            return new ContiguousX(index); }
    
        double a[] = new double [SIZE];
        double b[] = new double [SIZE];
        double c[] = new double [SIZE];
    };
    

    If you want to lessen the burden on the GC, you can also cache all instances of ContiguousX. It depends pretty much on the aptitude of the JIT compiler if the ContiguousX objects are allocated on the heap at all — they might well live in the stack, in this case the overhead is negligible. As a last resort, you can define an alternative interface for fast access:

    interface FasterArrayOfX {
        double getA(int index);
        double getB(int index);
        double getC(int index);
    };
    
    class FasterContiguousArrayOfX extends ContiguousArrayOfX implements FasterArrayOfX {
       // Exercise left to the reader
    };
    

    By programming against an interface you are always free to choose the storage later on.

    It is rather straightforward to write a code generator for any given class layout. The code above can be used as boilerplate, only the method and array declarations are dependent on the class layout you want to obtain. I am not aware of any existing tool.

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

Sidebar

Related Questions

I would like to know if it could be possible to add a file
I would like to know if it is possible to minimise my python program
I would like to know how is possible to read a file placed in
I would like to know if its possible to write a nested select statment?
I would like to know if its possible to clear the current information stored
I would like to know is it possible to add css to one of
Hi I would like to know if its possible to do something similar to
I would like to know how or if it is possible to use selectors
I would like to know if the following is possible in any of the
I would like to know if it's possible to download a file from a

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.