codiyer 发表于 2008-4-27 00:20:27

关于全局变量的疑问

关于全局变量这个东西有些地方还是不太清楚,请高人指点
全局变量在另一个vi里调用的时候会不会在内存中复制一份?
如果会复制,是不是每调用一次都要复制一份?
如果全局变量是一个队列,调用的时候会不会把整个队列的内容给复制一份?

cpubbs 发表于 2008-4-27 10:27:45

它应该只有一个内存中的位置,然后每次读的是相同的区域!如果要复制的话,它应该就读不到变化后的数据了!:handshake

站立的鱼 发表于 2008-4-28 16:30:54

应该是不会复制的,只是读同一个位置的值··

labc 发表于 2008-4-29 14:03:54

Avoiding Race Conditions
A race condition occurs when two or more pieces of code that execute in parallel change the value of the same shared resource. Because the outcome of the VI depends on which action executes on the shared resource first, race conditions cause unpredictability. Often, race conditions occur with the use of local and global variables or an external file, although race conditions can exist any time more than one action updates the value of the same stored data. The following block diagram shows an example of a race condition with a local variable.
请参考 http://zone.ni.com/reference/en-XX/help/371361D-01/lvhowto/race_conditions/

[ 本帖最后由 labc 于 2008-4-29 14:06 编辑 ]

codiyer 发表于 2008-4-29 14:55:02

谢谢楼上各位,如果不复制我就不用担心队列在两个程序之间通信会影响性能的问题了,至于变量之间的竞争在我的程序里影响不是太大
页: [1]
查看完整版本: 关于全局变量的疑问