Re: C++ in kernel (was Re: exception in a device driver)

Anthony Barbachan (barbacha@Hinako.AMBusiness.com)
Sat, 16 Jan 1999 20:36:46 -0500


-----Original Message-----
From: Chip Salzenberg <chip@perlsupport.com>
To: Alexander Viro <viro@math.psu.edu>
Cc: Oliver Xymoron <oxymoron@waste.org>; Anthony Barbachan
<barbacha@Hinako.AMBusiness.com>; scherrey@proteus-tech.com
<scherrey@proteus-tech.com>; tytso@mit.edu <tytso@mit.edu>;
linux-kernel@vger.rutgers.edu <linux-kernel@vger.rutgers.edu>;
alan@lxorguk.ukuu.org.uk <alan@lxorguk.ukuu.org.uk>
Date: Saturday, January 16, 1999 1:35 AM
Subject: Re: C++ in kernel (was Re: exception in a device driver)

>According to Alexander Viro:
>> On Sat, 16 Jan 1999, Chip Salzenberg wrote:
>> > Stroupstrup's design rule: "Constructors acquite resources;
>> > destructors release them."
>>
>> So, you are going to allocate an object in stack for each
>> semaphore you are holding?
>
>Yup.
>
>> shitload of overhead even if we'll do it in assembler
>
>I doubt that very strongly. Consider that the object need not be
>polymorphic; all it needs is a pointer member. And if you use a
>template class, you don't even need the pointer, so it'll be 100% as
>efficient as the C version (except one byte for the object itself
>(zero-length objects are not allowed (yet))).
>

Why even bother with a templete class? A regular class should be fine, and
inherit it in any children that need to be different for any reason. You
may even be able to eliminate the need for this particular class. And some
compilers do allow zero-byte classes as an optimization.

>Given:
>
> template <semaphore_t *SEM>
> class hold {
> public:
> hold() { down(SEM); }
> ~hold() { up(SEM); }
> };
>
>The code would look like:
>
> void random_function()
> {
> hold<&one_semaphore> hold1;
> hold<&other_semaphore> hold2;
> // ...
> }
>
>--
>Chip Salzenberg - a.k.a. - <chip@perlsupport.com>
> "When do you work?" "Whenever I'm not busy."
>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/