结构和速度 [英] Structures ans speed

查看:76
本文介绍了结构和速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模拟项目,其中数据可以自然地保存在
结构中进行处理。有多种功能需要参与
。执行速度是一个问题。我是否会因为使用
结构而受到重创?是否有一种传递结构的优选方式(或者说是
指针?)可以加快程序的速度?


我对C ++来说相对较新。所以,如果你有时间,细节(或

参考)将不胜感激。在任何情况下,任何帮助都是非常值得赞赏的。


Fred

解决方案

在文章< ea ************************* @ posting.google.com> ,Fred Bennett写道:

我有一个模拟项目,其中数据自然可以保存在
结构中进行处理。有涉及多个功能的电话。执行速度是一个问题。我是否会因为使用
结构而受到重创?是否有一种传递结构(或指针?)的首选方法可以加快程序的速度?
指针和引用通常会在将

作为参数传递给函数时使用,从而提高速度。最好只是通过地址传递地址而不是邮寄整个房子(可以这么说)


静态处理通常会超过动态处理。创建和

内存的破坏总是会占用cpu周期所以你可以用更多的钱来减少你处理处理所需的cpu周期。
我对C ++来说相对较新。所以,如果你有时间,细节(或
参考)将不胜感激。在任何情况下,任何帮助都非常值得赞赏。



我通过经验和听别人聆听的一般规则

我看了指导就是始终首先编码正确性

然后优化最后。它适用于我,但你的YMMV。学习和使用你学到的东西来学习知识,所以时间和练习将提高你的理解。这是我能提供的最好的帮助。


C Johnson

-

echo" qr **** *****@rkpvgr.pbz" | rot13

----- =通过Newsfeeds.Com发布,未经审查的Usenet新闻= -----
http://www.newsfeeds.com - 世界排名第一的新闻组服务!

----- ==超过100,000新闻组 - 19种不同的服务器! = -----


Fred Bennett写道:

我有一个模拟项目,其中数据可以自然地保存在
中加工结构。有涉及多个功能的电话。执行速度是一个问题。我是否会因为使用
结构而受到重创?是否有一种传递结构(或指针?)的首选方法可以加快程序的速度?

我对C ++来说相对较新。所以,如果你有时间,细节(或
参考)将不胜感激。在任何情况下,任何帮助都很受欢迎。




如果你使用C ++为什么要使用带有数据的结构,为什么不用真正的

带有会员功能的课程?


不,通常没有罚款。传递许多指针或变量

周围通常会花费相同数量或更多的时间,而不是通过指针或结构引用传递

。但通常你不希望将b
作为副本传递给它们。


你还必须记住它将是算法而且更多

您选择的复杂数据结构(如查找表),这将对您的运行时速度产生最明显的影响。


-

WW aka Attila


数据成员在内存中的对齐可能是一个问题。


对于英特尔-32处理器数据成员的最佳性能必须从

4字节边界开始,编译器必须为数据添加填充字节

align - (希望 - 对于MS编译器,这是默认内存对齐)。

如果您的程序使用SIMD(单指令多数据)之类的东西

命令 - SIMD的数据必须在16字节边界上对齐以获得更好的效果

性能 - 否则它不会受益于SIMD。


检查处理器/编译的自然数据对齐r并使用适当的

编译器代码生成选项。

Viatcheslav

" Fred Bennett" < FM ******* @ att.net>在消息中写道

新闻:ea ************************* @ posting.google.co m ... < blockquote class =post_quotes>我有一个模拟项目,其中数据可以自然地保存在
结构中进行处理。有涉及多个功能的电话。执行速度是一个问题。我是否会因为使用
结构而受到重创?是否有一种传递结构(或指针?)的首选方法可以加快程序的速度?

我对C ++来说相对较新。所以,如果你有时间,细节(或
参考)将不胜感激。无论如何,我们非常感谢任何帮助。

Fred



I have a simulation project in which data can naturally be held in
structures for processing. There are calls to multiple functions
involved. Execution speed is an issue. Do I take a big hit for usuing
structures? Is there a preferred way of passing the structures (or
pointers?) that would speed up the program?

I''m relatively new to C++. so, if you have time, detail (or
references) would be appreciated. In any case any help is much
appreciated.

Fred

解决方案

In article <ea*************************@posting.google.com> , Fred Bennett wrote:

I have a simulation project in which data can naturally be held in
structures for processing. There are calls to multiple functions
involved. Execution speed is an issue. Do I take a big hit for usuing
structures? Is there a preferred way of passing the structures (or
pointers?) that would speed up the program? Pointers and references generally will give you a speed increase when
used in the context of passing as parameters to functions. Better to just
pass the address than to mail the whole house (so to speak)

Static processing will usually beat out dynamic processing. Creation and
destruction of memory always eat cpu cycles so the more of that you can
minimize the more cpu cycles you have for "processing".
I''m relatively new to C++. so, if you have time, detail (or
references) would be appreciated. In any case any help is much
appreciated.


A general rule that I picked up through experience and listening to others
that I have looked up to for mentoring is to always code for correctness first
then optimize last. It works for me but your YMMV. Emperical knowledge comes
from learning and using what you learn so time and practice will improve your
understanding. That is about the best help I can offer.

C Johnson
--
echo "qr*********@rkpvgr.pbz" | rot13
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----


Fred Bennett wrote:

I have a simulation project in which data can naturally be held in
structures for processing. There are calls to multiple functions
involved. Execution speed is an issue. Do I take a big hit for usuing
structures? Is there a preferred way of passing the structures (or
pointers?) that would speed up the program?

I''m relatively new to C++. so, if you have time, detail (or
references) would be appreciated. In any case any help is much
appreciated.



If you work with C++ why do you use structures with data, why not real
classes with member functions?

And no, usually there is no penalty. Passing many pointers or variables
around will usually end up taking the same amount or more time than passing
around pointers or references to structures. But usually you do not want to
pass them around as copies.

You also have to remember that it will be the algorithms and the more
complex data structures (like lookup tables) you choose, which will have the
most noticeable effect on your runtime speed.

--
WW aka Attila


Data members alignment in memory may be an issue.

For Intel-32 processors data members for best perfomance must starts on
4-bytes boundaries and compiler must add padding bytes for data be
aligned - (hopefully - for MS compilers this is default memory alignment).
If your program is using things like SIMD (single instruction multiple data)
commands - data for SIMD must be aligned on 16-bytes boundaries for better
performance - otherwise it is no benefit from SIMD.

Check natural data alignment for your processor/compiler and use appropriate
compiler code generation option.

Viatcheslav
"Fred Bennett" <fm*******@att.net> wrote in message
news:ea*************************@posting.google.co m...

I have a simulation project in which data can naturally be held in
structures for processing. There are calls to multiple functions
involved. Execution speed is an issue. Do I take a big hit for usuing
structures? Is there a preferred way of passing the structures (or
pointers?) that would speed up the program?

I''m relatively new to C++. so, if you have time, detail (or
references) would be appreciated. In any case any help is much
appreciated.

Fred



这篇关于结构和速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆