Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buffer = (double*) malloc((r + r + r) * sizeof(double *) +
- (r*r + r*r + r*r) * sizeof(double));
- if(buffer == NULL) {
- printf("out of memoryn");
- return 0;
- }
- for(i = 0, j = 0; i < r; i++) {
- a[i] = &buffer[j];
- j+=r;
- }
- for(i = 0; i < r; i++) {
- b[i] = &buffer[j];
- j+=r;
- }
- for(i = 0; i < r; i++) {
- c[i] = &buffer[j];
- j+=r;
- }
- a = buffer[j];
- b = buffer[j + r];
- c = buffer[j + r + r];
- double* all = (double*) malloc( 3*r*r*sizeof(double));
- double *p1 = all;
- double *p2 = &all[r*r];
- double *p3 = &all[2*r*r];
- size_t r = ...;
- double (*a)[r] = NULL;
- double (*b)[r] = NULL;
- double (*c)[r] = NULL;
- double (*backing_store)[r][r] = malloc(3 * sizeof *backing_store);
- if (!backing_store)
- {
- // panic and exit
- }
- a = backing_store[0];
- b = backing_store[1];
- c = backing_store[2];
- a[i][j] = ...;
- printf("%fn", b[x][y]);
- free(backing_store);
- #define R ...
- double (*a)[R] = NULL;
- double (*b)[R] = NULL;
- double (*c)[R] = NULL;
- double (*backing_store)[R][R] = malloc(3 * sizeof *backing_store);
- if (!backing_store)
- {
- // panic and exit
- }
- a = backing_store[0];
- b = backing_store[1];
- c = backing_store[2];
- double *a = NULL;
- double *b = NULL;
- double *c = NULL;
- double *backing_store = malloc(3 * r * r * sizeof *backing_store);
- if (!backing_store)
- {
- // panic
- }
- a = backing_store;
- b = backing_store + r * r;
- c = backing_store + 2 * r * r;
- a[i*r+j] = ...;
- printf("%fn", b[x*r+y]);
- free(backing_store);
- double (*Memory)[r][r] = malloc(3 * sizeof *Memory);
- // Now Memory points to three r-by-r arrays of double.
- double (*a)[r] = Memory[0];
- double (*b)[r] = Memory[1];
- double (*c)[r] = Memory[2];
- double *(*PointerMemory)[r] = malloc(3 * sizeof *PointerMemory);
- // PointerMemory points to three arrays of r elements of pointers to double.
- double (*ElementMemory)[r][r] = malloc(3 * sizeof *ElementMemory);
- // Set a to point to the first array of r elements of pointers to double.
- double *a[r] = PointerMemory[0];
- // Initialize the elements of a to point to rows of the first r-by-r array of double.
- for (i = 0; i < r; ++i)
- a[i] = ElementMemory[0][i];
- // Set b for the second array of pointers and the second array of double.
- double *b[r] = PointerMemory[0];
- for (i = 0; i < r; ++i)
- b[i] = ElementMemory[1][i];
- // Set c for the third arrays.
- double *c[r] = PointerMemory[0];
- for (i = 0; i < r; ++i)
- c[i] = ElementMemory[2][i];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement