LWN.net Logo

Object-oriented design patterns in the kernel, part 1

Object-oriented design patterns in the kernel, part 1

Posted Jun 2, 2011 0:13 UTC (Thu) by linusw (subscriber, #40300)
Parent article: Object-oriented design patterns in the kernel, part 1

Fun that my two regulator commits are used as vtable illustration, I vaguely knew the term vtable before, now I know I'm doing such.

I'm anticipating the follow-on articles to elaborate on how the outspaced macro container_of() performs the analog mechanism to super() from OOP...


(Log in to post comments)

Object-oriented design patterns in the kernel, part 1

Posted Jun 3, 2011 9:07 UTC (Fri) by jengelh (subscriber, #33263) [Link]

container_of is e.g. used for linked lists, where it merely gives the surrounding actual object to the linked list head, in other words, it is used like (Java)"class mydevice implements list_head" rather than "extends list_head", so it would not be quite like "super" :-)

Object-oriented design patterns in the kernel, part 1

Posted Jun 3, 2011 13:25 UTC (Fri) by linusw (subscriber, #40300) [Link]

Yeah, extends or super or whatever. The point is that it is in the object orient.

Object-oriented design patterns in the kernel, part 1

Posted Jun 6, 2011 3:56 UTC (Mon) by jmm82 (guest, #59425) [Link]

It is also used in many kernel subsystems when the base struct will have a pointer to a private struct where the driver can hold variables Specific to that driver. The base struct is like a super in this case and if all you have is a pointer to the private struct you can use container_of() to get the base struct.

Also, container_of is used with the kref code when deleting the struct which has embedded a kref for refence counting.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds