何為ERP

The main application window is controlled by a view (IActiveView).  ArcMap currently has two view objects: Map (data view) and PageLayout (layout view).  Each view has a ScreenDisplay object which performs drawing operations. The ScreenDisplay object also makes it possible for clients to create any number of caches.  A cache is an off screen bitmap representing the application's window.  Instead of drawing directly to the screen, graphics are drawn into caches, then the caches are drawn on the screen.  When the application's window is obscured模糊 晦涩 and requires redrawing, it is done so from the caches instead of from a database.  In this way, caches improve drawing performance - bitmap rendering is faster than reading and displaying data from a database.

 一个Cache是一个独立于屏幕的位图,代表着应用程序窗口.

ScreenDisplay可以是客户创建任意数量的Cache.

图象并不是直接画在屏幕上,而是先画在caches中,然后由caches画到屏幕上.

当应用程序窗口模糊需要重画的时候,直接从caches中而不是从database中进行.

通过这种方式,caches提高了效率---------位图渲染比从数据库中读显数据快得多.

In general, the Map creates three caches: one for all the layers, another if there are annotation or graphics, and a third cache if there is a feature selection.  A layer can create its own private cache if it sets ILayer::Cached equal to TRUE.  In this case, the Map will create a separate cache for the layer and groups the layers above and below it into different caches.

一般而言,地图建立三个caches:一个是为所有图层用的,另一个是在由annotation或graphics的时候用,第三个是为selection准备的.

如果图层把它的cached属性设为TRUE,这个图层(Layer)可以用来建立自己的私有cache.这样,地图将为这个图层建立一个单独的cache,地图把其他图层放在它之前或之后的不同caches中.

IActiveView::PartialRefresh uses its knowledge of the cache layout to invalidate as little as possible.  IActiveView::Refresh , on the other hand, invalidates all the caches which is very inefficient.  Use PartialRefresh whenever possible. 

使用IActiveView::Refresh效率极低,它会使所有的caches无效重画.

尽可能使用IActiveView::PartialRefresh

Both PartialRefresh and Refresh call IScreenDisplay::Invalidate which sets a flag clients watch for.  Clients draw a cache from scratch (the database) if its flag is set to true, and from cache if the flag is set to false.

PartialRefresh和Refresh会调用IScreenDisplay::Invalidate ,如果设为true,客户端从数据库画一个cache,如果false,则从cache画一个cache

The following table shows the phases each view supports and what they map to:

phaseMapLayout
esriViewBackground  Map grids Page/snap grid
esriViewGeography LayersUnused
*esriViewGeoSelection Feature selectionUnused
esriViewGraphics  Labels/graphicsGraphics
esriViewGraphicSelection Graphic selectionElement selection
esriViewForeground  UnusedSnap guides

To specify multiple draw phases, combine individual phases together using a bitwise OR. This is equivalent to adding together the integer enumeration values. For example, pass 6 to invalidate both the esriViewGeography (2) and esriViewGeoSelection (4) phases.

可以通过OR组合使用参数.

Use the data parameter to invalidate just a specific piece of data.  For example, if a layer is loaded and its cache property is set to TRUE, this layer alone can be invalidated.  A tracking layer is a good example of this.

使用参数,只会使某些数据无效重画,例如,如果一个图层被加载进来并且其cached属性设为TRUE,这个图层可以单独被invalidated,A tracking layer就是一个极好的例子.

The envelope parameter specifies a region to invalidate.  For example, if a graphic element is added, it is usually only necessary to invalidate the immediate area surrounding the new graphic.

 envelope参数指定了一个重画的区域.例如,如果一个元素被添加了,只需要重画元素周围的区域.

Both the data and envelope parameters are optional. 

*When selecting features, you must call PartialRefresh twice, once before and once after the selection operation.

选择元素的时候,你必须使用PartialRefresh两次,一次在选择操作之前,一次在选择操作之后.

In Visual Basic specify a phase of 6 to invalidate both the esriViewGeography (2) and the esriViewGeoSelection (4). 

  pActiveView.PartialRefresh esriViewGeography + esriViewGeoSelection, Nothing, Nothing 

which is the same as:

  pActiveView.PartialRefresh 6, Nothing, Nothing

Below are several usage examples in Visual Basic.

Map:

Refresh layer          pActiveView.PartialRefresh esriViewGeography, pLayer, Nothing 
Refresh all layers     pActiveView.PartialRefresh esriViewGeography, Nothing, Nothing 
Refresh selection      pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
Refresh labels         pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing

PageLayout:

Refresh element        pActiveView.PartialRefresh esriViewGraphics, pElement, Nothing
Refresh all elements   pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
Refresh selection      pActiveView.PartialRefresh esriViewGraphicSelection, Nothing, Nothing

 

 
The example shows how to select and refresh graphics and features using PartialRefresh.
<think>好的,用户现在想了解栈的概念及其与递归和迭代的关系,还问到了栈的数据结构定义以及它在递归和迭代中的作用。首先,我需要回顾之前关于递归和迭代的讨论,并结合用户提供的引用内容来组织回答。 用户之前的问题是关于递归和迭代的区别,现在转向栈的相关内容,说明他们可能在学习算法或数据结构,想深入理解这些结构之间的联系。用户提供的引用中提到了递归依赖系统调用栈,迭代使用循环结构,栈溢出风险等,这些都需要在回答中体现。 首先,栈的定义。栈是一种LIFO的数据结构,基本操作是push和pop。需要简明扼要地解释,可能引用用户提供的引用[3]中的内容,比如操作系统用栈保存递归信息。数据结构定义部分,可以举例子,比如数组或链表实现,但用户可能更关注逻辑结构而非具体实现。 接下来,栈在递归中的作用。这里要强调递归函数调用时的栈帧,每次调用压栈,返回时弹栈。引用[3]提到终止条件的重要性,否则栈溢出,这点要强调。可能引用用户给的例子,比如阶乘递归的栈使用情况,以及如何导致栈溢出。 然后是栈在迭代中的作用。用户提供的引用[4]提到迭代使用循环代码,变量同时保存结果,这里可能需要解释显式栈的使用,比如用栈来模拟递归过程,如DFS的迭代实现。引用[3]中的遍历二叉树用迭代方式,需要栈来辅助,可以举例说明。 需要比较递归和迭代中栈的不同,递归用系统栈,而迭代用用户定义的栈,这样在控制内存方面更灵活。引用[2]提到递归是函数自调用,而迭代是代码段循环,这里可以联系起来。 可能还需要提到栈溢出的风险,递归的缺点,以及如何用迭代加栈来避免,比如用户引用[4]中的内容。同时,引用[5]中的阶乘递归例子可以用来说明栈的增长过程。 用户的问题还包括栈的数据结构定义,所以要确保这部分清晰,可能分点列出栈的特性,操作,然后自然过渡到在递归和迭代中的应用。 最后,生成相关问题时要围绕栈、递归优化、转换方法等,帮助用户进一步学习。确保引用标记正确,参考用户提供的引用[1]-[5],但不需要全部引用,选择相关的部分即可。 需要检查是否有遗漏点,比如栈在迭代中的显式管理,比如回溯算法中的使用,或者表达式求值等例子,但可能超出当前问题范围。保持聚焦在递归和迭代的关系上。 总结回答结构:定义栈,分点说明在递归和迭代中的作用,比较两者的差异,应用场景,最后相关问题。</think>### 栈的概念及其与递归、迭代的关系 --- #### 一、栈的数据结构定义 **栈(Stack)** 是一种遵循 **后进先出(LIFO)** 原则的线性数据结构,核心操作包括: 1. **入栈(Push)**:将元素添加到栈顶。 2. **出栈(Pop)**:移除并返回栈顶元素。 3. **查看栈顶(Peek)**:返回栈顶元素但不移除。 **实现方式**: - **数组**:通过固定大小的连续内存实现。 - **链表**:通过动态节点链接实现(更灵活)。 --- #### 二、栈在递归中的作用 1. **递归的系统调用栈** - 递归函数每次调用自身时,系统会为其分配一个 **栈帧(Stack Frame)**,保存函数的局部变量、参数和返回地址。 - **示例**:计算阶乘 $n!$ 的递归函数 `factorial(n)` 调用时,栈中依次压入 `factorial(n)`, `factorial(n-1)`, ..., `factorial(0)` 的栈帧[^3]。 - **风险**:若递归深度过大(如计算 `factorial(10000)`),会导致 **栈溢出(Stack Overflow)**[^2]。 2. **递归终止条件与栈的关系** - 终止条件决定了递归何时停止压栈并开始逐层返回。例如: ```python def factorial(n): if n == 0: # 终止条件 return 1 return n * factorial(n-1) ``` 若缺少终止条件,栈会无限增长直至溢出[^3]。 --- #### 三、栈在迭代中的作用 1. **显式管理栈结构** - 迭代中可通过 **自定义栈** 模拟递归行为,解决需要回溯的问题(如深度优先搜索、二叉树遍历)。 - **示例**:二叉树前序遍历的迭代实现: ```python def preorder(root): stack = [root] while stack: node = stack.pop() if node: print(node.val) stack.append(node.right) # 右子节点先入栈(后处理) stack.append(node.left) # 左子节点后入栈(先处理) ``` 通过栈显式记录待访问节点[^3][^4]。 2. **迭代与递归的栈对比** | **维度** | **递归(系统栈)** | **迭代(显式栈)** | |----------------|-------------------------------|-------------------------------| | **控制权** | 由系统自动管理 | 由程序员手动管理 | | **灵活性** | 受限(依赖语言栈大小) | 灵活(可动态调整栈容量) | | **适用场景** | 代码简洁的分治问题 | 需避免栈溢出或需精细控制的问题 | --- #### 四、栈在算法中的典型应用 1. **递归相关算法** - 分治算法(如快速排序)、树/图的深度优先遍历(DFS)、回溯算法(如八皇后问题)[^1][^3]。 2. **迭代相关算法** - 深度优先遍历的迭代实现、表达式求值(逆波兰表示法)、括号匹配校验[^4][^5]。 --- #### 五、栈与递归、迭代的关系总结 - **递归是隐式使用系统栈的迭代**,而 **迭代是显式使用自定义栈的递归**。 - **优化方向**: - 递归可通过 **尾递归优化** 减少栈深度(需语言支持,如Scheme、Scala)[^2]。 - 迭代通过自定义栈避免系统栈的限制,适合处理大规模数据。 --- **相关问题** 1. 如何用栈实现递归算法的迭代版本? 2. 尾递归优化如何减少栈空间占用? 3. 哪些场景下必须使用显式栈替代递归? 4. 栈溢出有哪些常见原因及解决方法? --- : 递归与迭代的选择需结合问题结构和性能需求。 [^2]: 递归的栈深度与时间复杂度需平衡[^3]。 [^3]: 显式栈提供更灵活的内存控制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值