结构VS级结构、VS

2023-09-04 22:32:30 作者:色混@

这适用于.NET。 我期待写一个空间映射应用程序。将有几个多边形在内存中一次(30个数量级 - 50多边形)。每个polgon具有的LatLong点的集合。集合的范围可以从10至200个多边形。不过,也有很多的计算,将使用点来完成的,这就是为什么(性能),我想使的LatLong一个结构。但是我厌倦做大量的LatLong的,这将是在内存中。任何有识之士这将是AP preciated。 总结一下:我想知道如果我shold使经纬度一个结构,因为我想ONT的计算,或一类,因为latLongs的数量,这将是在内存中的一个表现。

This applies .NET. I am looking to write a spatial mapping application. There will be several polygons in memory at once (on the order of 30 - 50 polygon). each polgon has a collection of LatLong points. the collection can range from 10 to 200 per polygon. However, there are alot of calculations that will be done using the points, which is why (for performance) I want to make the LatLong a struct. However I am weary do to the large number of LatLong that will be in memory. Any insight to this will be appreciated. To recap: I want to know if I shold make the LatLong a struct because I want performance ont the calculation, or a class because of the number of latLongs that will be in memory at one.

推荐答案

这个问题的答案是要依赖于你的资源的优先级,什么在类/结构,以及你如何使用它。我建议你​​找出你的内存/性能资源都是这样,然后做了很多这两种方案的测试,看看它们是如何在这些资源参数。如果可能的话,尝试测试你期望来执行实际操作。

The answer to this is going to depend on your resource priorities, what's in the class/struct, and how you're using it. I suggest you figure out what your memory/performance resources are like, then do a lot of testing of both implementations to see how they fit in those resource parameters. If possible, try to test the actual operations you expect to perform.

MSDN还提供有关何时以及何时不使用结构一些很好的指导。的从文章:

不要定义结构,除非类型有以下所有的   特点:

Do not define a structure unless the type has all of the following characteristics:   这在逻辑上重新presents一个值,类似于原始类型   (整数,双,等)。   在它有一个实例大小小于16字节小。   这是不可改变的。   它不会必须频繁装箱。    It logically represents a single value, similar to primitive types (integer, double, and so on). It has an instance size smaller than 16 bytes. It is immutable. It will not have to be boxed frequently.