请教动态事件与静态事件的效率? Topic is solved

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
Loaden
I live to help wx-kind
I live to help wx-kind
Posts: 177
Joined: Tue Feb 19, 2008 10:21 am
Location: China

请教动态事件与静态事件的效率?

Post by Loaden » Sun Oct 12, 2008 1:12 am

效率指两方面:
1 执行速度的快慢
2 生成可执行文件的大小

我在一个示例程序中对静态事件和动态事件两种方式生成的文件大小进行对比时发现:使用静态事件生成565KB,而动态事件生成566KB。看起来不相上下。

有研究过这方面的吗,给大伙说说或给一下这方面的参考信息。谢谢!

另,大家都喜欢什么样的事件映射方式呢?
Life is not fair, get used to it.

chess360
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Oct 02, 2008 12:07 pm

Post by chess360 » Sun Oct 12, 2008 4:15 am

可以参看event.h和event.cpp。

Event Table 用array,用for-loop找对应的function:

Code: Select all

        for (size_t n = 0; n < count; n++)
        {
            if ( wxEvtHandler::
                    ProcessEventIfMatches(*eventEntryTable[n], self, event) )
            {
                return true;
            }
        }
Connect 则用wxList,也是一个个找对应的function:

Code: Select all

        node = node->GetNext();

        if ((event.GetEventType() == entry->m_eventType) && (entry->m_fn != 0))
        {
            wxEvtHandler *handler =
#if !WXWIN_COMPATIBILITY_EVENT_TYPES
                                    entry->m_eventSink ? entry->m_eventSink
                                                       :
#endif
                                                         this;

            if ( ProcessEventIfMatches(*entry, handler, event) )
            {
                return true;
            }
效率应该是差不多的,各种平台、编译器也可能有分别。

两者的分别,是Event Table可读性较好;而Connect则较灵活(),请参考wxBlog:
http://wxwidgets.blogspot.com/2007/01/i ... nnect.html

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Sun Oct 12, 2008 5:23 am

楼上讲得精辟~学习了~

个人强烈偏好动态事件,也多次用它取消或改变事件的关联,对它爱不释手。

-Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

bloodlee
Experienced Solver
Experienced Solver
Posts: 77
Joined: Thu Nov 30, 2006 10:49 am
Location: Shenzhen, CHN

Post by bloodlee » Mon Oct 13, 2008 6:15 am

动态事件相当的灵活!
现在经常写Handler-View的结构. View只是一个壳!

Post Reply