Kill命令
kill
命令从内存中删除变量,并可用于从磁盘中删除它们。其基本形式是:
KILL expression 复制代码
- 要删除的一个或多个变量。
KILL x KILL x,y,z 复制代码
ClassMethod Kill() { k ^color s ^color(1) = "red" s ^color(1, 1) = "yellow" s ^color(1, 2) = "green" s a = 1, b = 2, c = 3, d = 4, e = 5 k a,b,d,^color(1) w " a = ", $d(a), " b = ", $d(b), " c = ", $d(c), " d = ", $d(d), " e = ", $d(e),! w " ^color(1) = ", $d(^color(1)), " ^color(1, 1) = ", $d(^color(1, 1)), " ^color(1, 2) = ", $d(^color(1, 2)),! } 复制代码
- 删除多维数组,进程global,global节点,删除多维数组,进程global,global节点时,会自动删除该节点的所有从属节点,以及仅包含指向已删除节点的指针的前一个节点。
ClassMethod Kill1() { k a, ^b, ^||c s a = "food", a(1) = "fruit", a(2) = "vegetables" s a(1, 1) = "apple", a(1, 1, 1) = "pear", a(1 ,2) = "banana" s a(2, 1) = "watermelon" s ^b = "food", ^b(1) = "fruit", ^b(2) = "vegetables" s ^b(1, 1) = "apple", ^b(1, 1, 1) = "pear", ^b(1 ,2) = "banana" s ^b(2, 1) = "watermelon" s ^||c = "food", ^||c(1) = "fruit", ^||c(2) = "vegetables" s ^||c(1, 1) = "apple", ^||c(1, 1, 1) = "pear", ^||c(1 ,2) = "banana" s ^||c(2, 1) = "watermelon" w "k之前",! zw a, ^b, ^||c kill a(1), ^b(2), ^||c(1) w "k之后",! zw a, ^b, ^||c } 复制代码
- “
独占Kill
”的特殊终止形式会删除除指定变量之外的所有局部变量。不能指定进程私有全局变量、全局变量或特殊变量,多维数组。
KILL (x) 复制代码
ClassMethod Kill2() { s a = 1, b = 2, c = 3, d = 4, e = 5 k (a,e) zw w !," a = ", $d(a), " b = ", $d(b), " c = ", $d(c), " d = ", $d(d), " e = ", $d(e),! } 复制代码
- 不带参数的
kill
命令将删除所有局部变量。它不会删除进程私有全局变量、全局变量或用户定义的特殊变量。
KILL 复制代码
ClassMethod Kill3() { k ^color s ^color(1) = "red" s ^||color(1) = "yellow" s a = 1, b = 2, c = 3, d = 4, e = 5 w "k之前" w k w !,"k之后",! w zw ^color zw ^||color } 复制代码
- 按值传递变量,在被调用的函数或子例程的上下文之外,
kill
列表中的变量没有任何效果。这是因为在调用函数或子例程时,Caché会自动保存相应实际变量的当前值。然后,它会在退出函数或子例程时自动恢复保存的值。
ClassMethod Kill4() { s a = "yx" w !,"执行sub之前: ", $data(a) d sub(a) w !,"执行sub之后: ", $data(a) q sub(x) w !,"k之前 x: ", $data(x) k x w !,"k之后 x: ", $data(x) q }