Paste number 142952: Crxns

Paste number 142952: Crxns
Pasted by: hcurtis
When:8 years, 3 months ago
Share:Tweet this! | http://paste.lisp.org/+32AW
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 dynamic. 
The version of fast4-g.c serving as the base for my corrections is the one shown in commit 56495.

Any feedback is welcome.

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++)

/* Lines 2943 & 2944 */
for (i=0; i<11; i++)
    BU_LIST_INIT(&group_head[i].l);


My corrections:
/* I will define this constant near the top of the program */
#define	STARTER_NUMBER_OF_MEMORY_SPACES	11

/* My new corrections to line 213 */
static struct wmember *group_head = (struct wmember *) NULL; /* Lists of regions for groups */
group_head = (struct wmember *) bu_malloc(sizeof(struct wmember) * STARTER_NUMBER_OF_MEMORY_SPACES, "allocate heap memory for wmembers"); 

/* I will need something like this as well, but I don't yet know where to get sizeOfNewMemorySpace */
static struct wmember *group_head2 = (struct wmember *) NULL; /* New lists of regions for groups if the original one needs to be resized */
group_head2 = (struct wmember *) bu_realloc(group_head, sizeOfNewMemorySpace, "reallocate heap memory for wmembers");
group_head = group_head2;

/* Line 907+ should be deleted or commented out */

/* My corrections to lines 2943+ */
int i = 0;
while (&group_head[i].l != NULL) {
    BU_LIST_INIT(&group_head[i].l);
    i++;
}

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.