[Tickit-dev] Refcounting Pens
Paul "LeoNerd" Evans
leonerd at leonerd.org.uk
Sun Aug 16 17:28:30 BST 2015
One of the latest additions to the C libtickit is a pair of functions
TickitPen *tickit_pen_ref(TickitPen *pen);
void tickit_pen_unref(TickitPen *pen);
(see http://home.leonerd.org.uk/code/libtickit/doc/tickit_pen_ref.3.html)
Between them, these implement a refcount behaviour on a pen instance. A
pen starts with refcount 1, so normally you can just replace a call to
_destroy with _unref and things work as you'd expect.
But now, you can use _ref instead of _clone, to return a pointer to the
same pen instance with its refcount bumped, instead of allocating and
copying an entire new one. Much cheaper on memory and CPU time. This is
useful in the common case of not mutating pens after they're
constructed.
RenderBuffer is already updated to use it.
I'm vaguely considering on some sort of ability to have an immutable
pen, to make it safer for this kind of operation. What does anyone
think to this?
--
Paul "LeoNerd" Evans
leonerd at leonerd.org.uk
http://www.leonerd.org.uk/ | https://metacpan.org/author/PEVANS
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://mail.leonerd.org.uk/pipermail/tickit-dev/attachments/20150816/4dfc9ef7/attachment.sig>
More information about the Tickit-dev
mailing list