wjmarlett has asked for the wisdom of the Perl Monks concerning the following question:

I inherited some Perl/TK code that creates text widgets on a canvas. Each time it updates, it deletes the tags. After running for a couple days the widgetID exceeds the maximum unsigned value for an int (goes negative) and subsequent function calls using the ID fail. Is there a way to get the widgetID to wrap? Rewriting the canvas appears to fix the problem. Thanks Christoph.

Replies are listed 'Best First'.
Re: Perl/Tk widgetId
by GrandFather (Saint) on Jun 15, 2009 at 03:00 UTC

    Can you show us some sample code that demonstrates the problem?

    It may be that you have to manage tags in some fashion so that deleted tags can be reused. One way to do that would be to keep a high water mark variable and a stack of available tags. If the stack is empty use the tag number from the high water mark variable and bump the variable. When you delete a tag, push it onto the stack.


    True laziness is hard work
Re: Perl/Tk widgetId
by lamprecht (Friar) on Jun 15, 2009 at 07:45 UTC
    Hi,

    I assume you are talking about the item-id returned by the createITEM - method. It would not be very useful having these wrap, because if they did, how would you ensure their uniqueness. Concerning your problem: If you can find a point in your program where all items are deleted, you could recreate the canvas there and get a new id-counter.

    Cheers, Christoph