aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-06-09 18:11:34 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-06-09 18:51:35 +1200
commitd29cb84f52f93e060c2ec0f020f56fea0636428d (patch)
tree6eb70e2bf52cfe4b7ac4d5d07ce99f77cc397e90
parentabed235f6918e932020f93f5be4f358637af8144 (diff)
downloadfractal-gen-d29cb84f52f93e060c2ec0f020f56fea0636428d.tar.xz
Moved mallocs inside their if()s, various whitespace removals
-rw-r--r--bship.c1
-rw-r--r--fractal-gen.c20
-rw-r--r--mbrot.c1
3 files changed, 6 insertions, 16 deletions
diff --git a/bship.c b/bship.c
index f1cab2d..1d16ae2 100644
--- a/bship.c
+++ b/bship.c
@@ -21,7 +21,6 @@ void *generate_bship_section(void *section)
z = cpow( cabsf(crealf(z)) + I*cabsf(cimagf(z)) , d->power) + c;
}
-
d->data[idx++] = (255*i)/d->iterat;
}
}
diff --git a/fractal-gen.c b/fractal-gen.c
index 79f2de7..6ce9867 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -44,11 +44,8 @@ int main(int argc, char **argv)
assert(iterat > 0);
assert(cores > 0);
- // Allocated memory for sections, bailing upon failure
- sections = malloc(sizeof(data_section)*cores);
-
-
- if (sections == NULL)
+ // Allocate memory for sections
+ if ((sections = malloc(sizeof(data_section)*cores)) == NULL)
{
perror("malloc");
return EXIT_FAILURE;
@@ -65,18 +62,13 @@ int main(int argc, char **argv)
sections[i].power = power;
sections[i].iterat = iterat;
-int s;
-
// A bit complex, icky, will document later
if (i < (size%cores))
- s = (size*((int)(size/cores)+1));
+ x = (size*((int)(size/cores)+1));
else
- s = (size*(int)(size/cores));
-
- sections[i].data = malloc(s);
-
+ x = (size*(int)(size/cores));
- if (sections[i].data == NULL)
+ if ((sections[i].data = malloc(x)) == NULL)
{
fprintf(stderr, "\n");
perror("malloc");
@@ -88,7 +80,7 @@ int s;
free(sections);
return EXIT_FAILURE;
}
- fprintf(stderr, " -> Thread #%d (%d)\r", i+1, s);
+ fprintf(stderr, " -> Thread #%d (%d bytes data area)\r", i+1, x);
pthread_create(&sections[i].thread, NULL, generator, &(sections[i]));
}
diff --git a/mbrot.c b/mbrot.c
index fb7d668..6722b55 100644
--- a/mbrot.c
+++ b/mbrot.c
@@ -8,7 +8,6 @@ void *generate_mbrot_section(void *section)
double a,b;
double complex z,c;
-
for (y = d->core, b = (d->core*(3.5f/d->size)-1.75f); y < d->size; b+=((d->cores*3.5f)/d->size), y+=d->cores)
{
for (x = 0, a = -2.5f; x < d->size; a+=(3.5f/d->size), x++)