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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:21:19+00:00 2026-06-14T08:21:19+00:00

For some reason I think I have allRates is x*y*z length pointer to doubles

  • 0

For some reason I think I have allRates is x*y*z length pointer to doubles and rates is essentially a 3dimensional array. But I can’t recall exactly how this works.

// Allocate 3D Rate Array  
 double *allRates = malloc( x*y*z*sizeof(double) );
  if (!allRates) exit(1);
 double ***rates = malloc( x*sizeof(double **) );
  if (!rates) exit(1);

 for(i=0; i<x; i++) {
  rates[i] = malloc(y * sizeof(double *));
// Check rates[i] allocation?
  for(j=0; j<y; j++) {
   rates[i][j] = allRates + (i*y*z) + (j*z);
  }
 }

It runs properly… I’m just working on documentation and haven’t worked on this part of the code since March.

  • 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-14T08:21:20+00:00Added an answer on June 14, 2026 at 8:21 am
    // Allocate 3D Rate Array  
     double *allRates = malloc( x*y*z*sizeof(double) );
      if (!allRates) exit(1);
    

    allocates a block of memory large enough to hold x*y*z values of type double (if the dimensions are small enough; if the mathematical result of the product isn’t representable as a size_t, it allocates the remainder of that modulo SIZE_MAX + 1).

     double ***rates = malloc( x*sizeof(double **) );
      if (!rates) exit(1);
    

    allocates a block of memory large enough to hold x values of type double** (again, if x is small enough). Those are used as the indices for the first dimension.

     for(i=0; i<x; i++) {
      rates[i] = malloc(y * sizeof(double *));
    // Check rates[i] allocation?
    

    Checking the allocation is definitely advisable. If nothing fails, each rates[i] is made to point to a block of memory large enough to hold y pointers to double.

      for(j=0; j<y; j++) {
       rates[i][j] = allRates + (i*y*z) + (j*z);
      }
     }
    

    Each of the double*s rates[i][j] is made to point into the block allocated to allRates, at an offset of i*(y*z) + j*z elements, i times the size of an y×z-plane plus j times the length of a z-element row, so that rates[i][j] points to the first element of row j in plane i.

    If C99 is available, or y and z are compile-time constants, that would be simpler achieved by allocating

    double (*rates)[y][z] = malloc(x * sizeof *rates);
    

    with fewer indirections when addressing.

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

Sidebar

Related Questions

For some reason, I can't get ActionBarSherlock to work. I think I have it
I think there is a simple answer to this, but for some reason I
I think I'm missing something really obvious here... must be... but for some reason
I have what I think is a pretty simple migration. For some reason I
I think we may have trouble with our existing project. For some reasons we
for some reason (and I think I know why), when more than one row
For some reason, subversion is returning me error messages in what I think is
For some reason I can't detect I can't set a z index for any
I am working on an ASP.NET MVC application. For some reason, everytime I think
For some reason I can't get absolutely position elements with a z-index set to

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.