刷子创造有多贵? [英] How expensive is brush creation?

查看:57
本文介绍了刷子创造有多贵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做相当多的自定义绘画,这意味着我必须创建很多画笔(想想一个

目录中的每个文件系统对象) )每涂料。这有多贵?我应该找到一种方法来创建刷子一次,将它们存储在一个成员变量中,并在需要时使用它们吗?或者正在创建一个抛弃过程

,这不需要很多工作吗?


感谢您的信息。


Tom P.

I am doing quite a bit of custom painting and it means I have to
create a lot of brushes (think one for every file system object in a
directory) per paint. How expensive is this? Should I find a way to
create the brushes once, store them in an member variable, and use
them when I need them? Or is creating brushes a throw-away process
that doesn''t take a lot of work?

Thanks for the info.

Tom P.

推荐答案

On Tue,2008年8月5日10:54:38 -0700,Tom P.< pa*********** @ gmail.com写道:
On Tue, 05 Aug 2008 10:54:38 -0700, Tom P. <pa***********@gmail.comwrote:

我正在做相当多的自定义绘画,这意味着我必须

为每个绘制创建许多画笔(对于

目录中的每个文件系统对象都要考虑一个)。这有多贵?我应该找到一种方法来创建刷子一次,将它们存储在一个成员变量中,并在需要时使用它们吗?或者正在创建一个抛弃过程

,这不需要很多工作吗?
I am doing quite a bit of custom painting and it means I have to
create a lot of brushes (think one for every file system object in a
directory) per paint. How expensive is this? Should I find a way to
create the brushes once, store them in an member variable, and use
them when I need them? Or is creating brushes a throw-away process
that doesn''t take a lot of work?



衡量你提出的两个

实施时的速度差异是什么?你试图解决什么性能问题?


如果这些问题的答案是我还没有测量和/或没有

特定的性能问题,那么你就不用担心创建画笔的费用了。


Pete

What''s the speed difference when you measure your two proposed
implementations? What performance problem are you trying to solve?

If the answers to those questions are "I haven''t measured" and/or "no
particular performance problem", then you are premature in worrying about
the expense of creating a brush.

Pete


On 5 ao?t,19:54,Tom P. < padilla.he ... @ gmail.comwrote:
On 5 ao?t, 19:54, "Tom P." <padilla.he...@gmail.comwrote:

我正在做相当多的自定义绘画,这意味着我必须

为每个绘制创建了很多画笔(对于

目录中的每个文件系统对象都考虑一个)。这有多贵?我应该找到一种方法来创建刷子一次,将它们存储在一个成员变量中,并在需要时使用它们吗?或者正在创建一个抛弃过程

,这不需要很多工作吗?


感谢您的信息。
< br $>
Tom P.
I am doing quite a bit of custom painting and it means I have to
create a lot of brushes (think one for every file system object in a
directory) per paint. How expensive is this? Should I find a way to
create the brushes once, store them in an member variable, and use
them when I need them? Or is creating brushes a throw-away process
that doesn''t take a lot of work?

Thanks for the info.

Tom P.



这是非常昂贵的,不是因为刷子本身,而是

因为你'每次Paint事件都会给垃圾收集器送上所有刷子




你最好使用系统刷子,这是静态的。使用:


Brushes.Black


而不是:


刷b =新的SolidBrush( Color.Black)


如果您经常使用216

预定义颜色以外的相同颜色,您可以这样做(在静态类中,实例):


私有静态刷orangeyBrush;


公共静态刷橙色

{

get

{

if(orangeyBrush == null)

return(orangeyBrush = new

SolidBrush (Color.FromArgb(223,156,0)));

}

}


这模仿框架内部的作用(懒惰的初始化)。


Michel

It is VERY expensive, not because of the brushes themselves, but
because you''re feeding the Garbage Collector with all those brushes on
every Paint event.

You''d be better off using the system Brushes, which are static. Use:

Brushes.Black

instead of:

Brush b = new SolidBrush(Color.Black)

If you frequently use the same colors that are outside the 216
predefined ones, you can do this (in a static class, for instance):

private static Brush orangeyBrush;

public static Brush Orangey
{
get
{
if (orangeyBrush == null)
return (orangeyBrush = new
SolidBrush(Color.FromArgb(223,156,0)));
}
}

This mimics what the framework does internally (lazy initialization).

Michel


On 5 ao?t,20:01,Peter Duniho < NpOeStPe ... @nnowslpianmk.comwrote:
On 5 ao?t, 20:01, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:

On Tue,2008年8月5日10:54:38 -0700,Tom P.< padilla.he。 .. @ gmail.comwrote:
On Tue, 05 Aug 2008 10:54:38 -0700, Tom P. <padilla.he...@gmail.comwrote:

我正在做相当多的自定义绘画,这意味着我必须

创造了很多每个绘画刷(对于

目录中的每个文件系统对象一个)。这有多贵?我应该找到一种方法来创建刷子一次,将它们存储在一个成员变量中,并在需要时使用它们吗?或者正在创建一个抛弃过程

,这不需要很多工作吗?
I am doing quite a bit of custom painting and it means I have to
create a lot of brushes (think one for every file system object in a
directory) per paint. How expensive is this? Should I find a way to
create the brushes once, store them in an member variable, and use
them when I need them? Or is creating brushes a throw-away process
that doesn''t take a lot of work?



衡量两个建议的*

实施时的速度差异是什么? *你想解决什么性能问题?


如果这些问题的答案是我还没有测量和/或没有*

特定的性能问题,那么你就不用担心创建画笔的费用了。

Pete


What''s the speed difference when you measure your two proposed *
implementations? *What performance problem are you trying to solve?

If the answers to those questions are "I haven''t measured" and/or "no *
particular performance problem", then you are premature in worrying about*
the expense of creating a brush.

Pete



是的,我假设油漆意思是油漆事件。如果是油漆的话。如在

" image"或图片框例如,Pete的权利,改善

可能会妨碍可读性,但收益可以忽略不计。


Michel

Yes, I assumed "paint" meant "paint event". If it is "paint" as in
"image" or "picturebox" for instance, Pete''s right, the improvement
might hamper readability for a negligible gain.

Michel


这篇关于刷子创造有多贵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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