S
SG
Am 03.11.2012 14:33, schrieb James Kuyper:
I agree. Last time I checked, the Linux kernel included things like
(intrusive) reference counting for some kinds of objects. Of course,
explicitly invoking functions for incrementing and decrementing these
counters is error-prone. This could be done with a smart pointer class
in C++. In all fairness I have to mention that I noticed an
optimization used in the kernel code. Whenever a function passes a
pointer to a ref-counted object to another function in the sense that
"ownership is transferred", there is no need to increment the
ref-counter for the new copy of the pointer and decrement it when the
original pointer is destroyed. In C++11 you could get the same
behaviour with a "move-enabled" smart pointer class (a class that
provides a move constructor and a move assignment operator).
With respect to overhead of C++, I'd like to point out a nice report on
the subject:
http://www.open-std.org/jtc1/sc22/wg21/docs/TR18015.pdf
Cheers!
SG
[...]
The built-in C types fall into a number of categories, based upon which
operators work on them: arithmetic types, pointer types, array types,
functions. Operator overloads work best when they make something that is
of class type work like a member of one of those categories: extended
numeric types such as quaternions or arrays, smart pointers, containers,
or function objects. They only lead to confusion when used for other
purposes. I don't imagine there's much need for extended arithmetic
types in kernal programming. However, it seems to me that various kinds
of smart pointers or containers could be useful, unless they can't be
properly implemented. If there's any place where kernel code passes
around function pointers, passing around function objects might be a
reasonable alternative.
I agree. Last time I checked, the Linux kernel included things like
(intrusive) reference counting for some kinds of objects. Of course,
explicitly invoking functions for incrementing and decrementing these
counters is error-prone. This could be done with a smart pointer class
in C++. In all fairness I have to mention that I noticed an
optimization used in the kernel code. Whenever a function passes a
pointer to a ref-counted object to another function in the sense that
"ownership is transferred", there is no need to increment the
ref-counter for the new copy of the pointer and decrement it when the
original pointer is destroyed. In C++11 you could get the same
behaviour with a "move-enabled" smart pointer class (a class that
provides a move constructor and a move assignment operator).
With respect to overhead of C++, I'd like to point out a nice report on
the subject:
http://www.open-std.org/jtc1/sc22/wg21/docs/TR18015.pdf
Cheers!
SG