这是所有编程语言的基本问题,但我对VBA很熟悉。所以我使用vba代码。我对释放内存有一些疑问。当我们擦除或交换分配的内容时,性能是否降低? 像取消分配内存会降低性能吗?
方法我我们解除分配所分配的内存
sub my_function()
Dim a() as string
redim a(1 to 15)
'some for loop goes here aroung 50 iterations
erase a ' Deallocate the array
' some piece of code goes here may be 40 lines
end sub
方法II我们不解除分配任何内存
sub my_function()
Dim a() as string
redim a(1 to 15)
'some for loop goes here aroung 50 iterations
'some piece of code goes here may be 40 lines
end sub
方法III我们在dellocate内存最后的声明
sub my_function()
Dim a() as string
redim a(1 to 15)
'some for loop goes here aroung 50 iterations
'some piece of code goes here may be 40 lines
erase a 'deallocate the memory
end sub
方法我被擦除的问题,是否吃了任何巨大的循环?或更多的字节ram?或者我应该等待的子过程的结束,或者我应该去使用擦除语句
方法II有一个在子程序没有擦除语句,函数杀死在子过程,但我结束数组不需要数组直到函数结束,所以这是否足够快或优化?
方法三在第一只手表,人们都说它是一个愚蠢的事情,在为自己杀死在最后的子过程的结束dellocate,但我急切地想知道感谢
“More lines = bad” - 我不知道这种态度来自哪里。检查字符串变量长度作为检查字符串变量是否包含任何内容的方法是最佳实践,因为它比比较更快。 – JimmyPena