Re: [ANN] Fast C++ Delegate
От: Cyberax Марс  
Дата: 03.03.06 15:07
Оценка: 12 (1)
SchweinDeBurg wrote:
> By the way, these techniques are considered as 'fast' since they were
> able to avoid the heap memory allocation to store the member function
> pointer unlikely boost::function does.
Уже не does В CVS-версии добавили small buffer optimization для b::f,
теперь для небольших функциональных объектов (в том числе простых
делегатов) оно работает лишь в 3 раза медленнее FastDelegate'а с
CodeProject (до этого работало в 30 раз медленнее).

По сути код в этой статье повторяет код из текущего Boost'а
Posted via RSDN NNTP Server 2.0
Sapienti sat!
Re[2]: [ANN] Fast C++ Delegate
От: SchweinDeBurg Россия https://zarezky.spb.ru/
Дата: 03.03.06 15:15
Оценка: +1
Здравствуйте, Cyberax, Вы писали:

C>По сути код в этой статье повторяет код из текущего Boost'а


Ну сорьки. Я буст не пользую, так что сравнить не могу. Просто решил поделиться ссылкой, котора мне показалась интересной.
[ posted via RSDN@Home 1.1.4 stable SR1 r568, accompanied by silence ]
- Искренне ваш, Поросенок Пафнутий
[ANN] Fast C++ Delegate
От: SchweinDeBurg Россия https://zarezky.spb.ru/
Дата: 03.03.06 14:45
Оценка:
Fast C++ Delegate

An implementation of the fast C++ delegate which is portable and C++ Standard-compliant.

Don Cluston explained about the member function pointer and its behavior in the very well organized way in his article "Member Function Pointers and the Fastest Possible C++ Delegates ". In short, member function pointer can not be assigned into void * data pointer so a special care need to be taken to deal with member function pointer as a data (functor). Don's FastestDelegate is the really fastest possible delegate as he claimed but he leveraged reinterpret_cast<> to deceive the compiler, which he called it as 'horrible hack' by himself in his article.

Sometimes later, Sergey Ryazanov came up with a fast C++ delegate which is found to be as fast as Don's FastestDelegate but completely C++ Standard compliant. His technique is using a templatized static member function ('stub') to store/restore the function call information (return type, argument type, cv-qualifier and platform specific calling convention) at compile-time. Actually it isn't new as a similar approach had been already introduced by Rich Hickey in his article "CALLBACKS IN C++ USING TEMPLATE FUNCTORS", 1994. Rich called such a static member function as 'thunk' function. However, Sergey's technique is unique as he passed over member function call information through non-type template parameter. Unfortunately, not many commercially available compilers can support this truly C++ Standard feature. Thus his code is not really portable in that sense.

There is one more great article about how to implement C++ delegate here in CP. It is "Yet Another Generalized Functors Implementation in C++" by Aleksei Trunov. He explained and analyzed so well in detail about generalized functor requirements and problems of the existing delegates. His article inspired me to start implementing my own fast delegate which will be suggested here below.

By the way, these techniques are considered as 'fast' since they were able to avoid the heap memory allocation to store the member function pointer unlikely boost::function does.

[ posted via RSDN@Home 1.1.4 stable SR1 r568, accompanied by silence ]
- Искренне ваш, Поросенок Пафнутий
Re[2]: [ANN] Fast C++ Delegate
От: alexeiz  
Дата: 04.03.06 04:23
Оценка:
Здравствуйте, Cyberax, Вы писали:

C>В CVS-версии добавили small buffer optimization для b::f,

C>теперь для небольших функциональных объектов (в том числе простых
C>делегатов) оно работает лишь в 3 раза медленнее FastDelegate'а с
C>CodeProject (до этого работало в 30 раз медленнее).

Какие операции медленнее? Создание или вызов?
Re[3]: [ANN] Fast C++ Delegate
От: Cyberax Марс  
Дата: 04.03.06 14:37
Оценка:
alexeiz wrote:
> C>В CVS-версии добавили small buffer optimization для b::f,
> C>теперь для небольших функциональных объектов (в том числе простых
> C>делегатов) оно работает лишь в 3 раза медленнее FastDelegate'а с
> C>CodeProject (до этого работало в 30 раз медленнее).
> Какие операции медленнее? Создание или вызов?
И то, и другое. В B::F более общий случай функций — там часть параметров
функции может быть привязана, поэтому нужен виртуальный вызов менеджера.

Я у себя попробовал скрестить FastDelegate с B::F — в случае простого
делегата будет сразу вызываться целевая функция, в случае сложного
bind'а — обычный invoker из B::F. То есть получаем нулевой оверхед по
скорости. Вроде получилось, но мне лень проверять это на VC6 и прочих
древностях

Вот тред из Boost'овского списка рассылки про SBO:
http://news.gmane.org/find-root.php?message_id=%3cdotl3d%246ae%241%40sea.gmane.org%3e
(чего-то GMane сегодня глючит).
Posted via RSDN NNTP Server 2.0
Sapienti sat!
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.