Paste number 142975: Crxns

Paste number 142975: Crxns
Pasted by: hcurtis
When:8 years, 3 months ago
Share:Tweet this! | http://paste.lisp.org/+32BJ
Channel:None
Paste contents:
Raw Source | XML | Display As
I am converting some of the elements of BRL-CAD's fast4-g.c from stack allocated to dynamically allocated. 
Any feedback is welcome. I can show you my entire revised version of fast4-g.c if you'd like.
This is the code I am correcting. It comes from the version of fast4-g.c from commit 56495.
/* Line 213 */
static struct wmember group_head[11]; /* Lists of regions for groups */

/* Line 907 */
for (group_no=0; group_no < 11; group_no++)

/* Line 2943 */
for (i=0; i<11; i++)


My corrections:
/* My new declarations */
static int region_id_max = 0; /* Line 199 of my latest revised version of fast4-g.c */
static struct wmember *group_head_resizer = (struct wmember *) NULL; /* A variable to help point back to group_head if a memory-reallocation attempt fails; line 215 of my latest revised version of fast4-g.c */
static ssize_t numberOfGroups = 0; /* Line 232 of my latest revised version of fast4-g.c */

/* Replacement for line 213 of commit 56495; in my latest revised version of fast4-g.c, it is line 214 */
static struct wmember *group_head = (struct wmember *) NULL; /* Lists of regions for groups */ 
 
/* New code (lines 527-529 of my latest revised version of fast4-g.c) */
if (reg_id > region_id_max) {
    region_id_max = reg_id;
}

/* New code (lines 894-900 of my latest revised version of fast4-g.c) */
numberOfGroups = (ssize_t) ceil(region_id_max/1000.0);
group_head = (struct wmember *) bu_malloc(sizeof(struct wmember) * numberOfGroups, "allocate heap memory for group_head");

if (!group_head || ptr->region_id > region_id_max) {
    group_head_resizer = (struct wmember *) bu_realloc(group_head, sizeof(struct wmember) * numberOfGroups, "allocate heap memory for group_head");
    group_head = group_head_resizer;
    bu_log("ptr->region_id=%d region_id_max=%d numberOfGroups=%ld\n", ptr->region_id, region_id_max, numberOfGroups);
}

/* Correction to line 907 of commit 56495; in my latest revised version of fast4-g.c, it is line 925 */
for (group_no = 0; group_no < numberOfGroups; group_no++) {

/* Correction to line 2943 of commit 56495; in my latest revised version of fast4-g.c, it is line 2961 */
for (i = 0; i < numberOfGroups; i++)

/* New code (line 3006 of my latest revised version of fast4-g.c) */
bu_free(group_head, "free the group_head memory");

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.