From: Martin Z. <co...@mz...> - 2012-03-25 20:58:27
|
Hi Marcus! > I don't understand the realloc error handling in 'timer_add_widget' > (similar in 'timer_add').In the case of a realloc error 'TimerGroupWidgets' > was set to NULL. [...] I honestly just copied this from "timer.c". You're completely right, but being just faintly familiar with allocating and freeing memory in C (I mostly use higher programming languages), I hope that someone else chimes in. :) > Why shouldn't a new 'on hold' become 'active' in the same > loop if 'widget_timer_update' is called multible times? > And how would you guarantee that 'widget_timer_update' > will ever be called again (to replace 'on hold' by 'active') > if there is only one timer widget? While I don't understand the first part (probably some language barrier), your second point is valid. It was just a first idea to get things going. Still, I don't like the idea of designing a patch for the current problem (which could be as simple as changing "timer_add_widget" in "widget_timer.c" to "timer_add") and waiting for the problem to creep up again in another context. > Beside that I don't like the idea that third file functions > which made use of timer.c & timer_group.c (might be many) > have to make efforts to guarantee that they behave as exspected. Me neither. As I said, first idea... :) I do however quite like Mattias idea of using some sort of linked list. The attached image might be more clear than my words, but I'm thinking of this: each timer slot has a variable that points to the next timer slot (or to zero if it is the last one). There is an additional "main" pointer which points to the first timer slot (in red). On looping, the loop determines the first timer slot using the "main" pointer and then works its way through the linked list until it reaches a slot (the last one) whose pointer points to zero. If a timer slot is removed, the pointer of its predecessor is set to the removed slot's pointer. When a timer slot is added, it is added to the *beginning* of the list so it isn't processed prematurely. To make sure it will be processed in the next loop, the "main" pointer is set to the new slot. Already allocated memory would be determined and used just like before. Any comments? :) Martin -- www.mzuther.de www.radix-musik.de |