3 ms·
By block allocated array you mean something like a hybrid between a fixed-size array and a linked list stack? I'm not very familiar with tail recursion, so I'll
by chestervonwinch 9y ago
By block allocated array you mean something like a hybrid between a fixed-size array and a linked list stack? I'm not very familiar with tail recursion, so I'll take that as a suggestion to read more on it. The answer to your last question is that f2py was easy enough to use and something I'm already familiar with :)
- gravypod 9y agoBy block allocated array I mean. typedef struct { int x, y, z; } vec3; typedef struct { int size, i; vec3 items[]; } stack; static inline stack *stack_make(int size) { stack *s = malloc(sizeof(stack) + size * sizeof(vec3)); s->size = size; s->i = 0; } static inline bool stack_push(stack *s, vec3 *v) { if (s->size <= s->i) return false; s->items[s->i++] = *v; return true; } static inline vec3 *stack_pop(stack *s) { return s->i == -1 ? NULL : &s->items[s->i--]; } If you want to dynamically grow your stack size you can implement realloc to have your data set grow/shrink but I would recommend against that. Also note that this implementation is not ideal. You obtain a reference to the internal data in stack_pop. If you push something new to your stack your pointer value will change. stack_pop should be changed to stack_pop(s, &container_vector) and populate that for consistency.
- chestervonwinch 9y agoThe reason I didn't implement the stack with an array is that it has to be of size at most the number of voxels in the image volume. This is potentially much, much larger than size that the stack will grow. In any case, I implemented the array stack along the lines of your post (with some modifications), and it yields some minor improvements (about 0.014 less seconds on average).