1
A
回答
2
當然,創建一個包含9999個元素的數組將比使用999的數組使用更多的內存。我懷疑這不是你的問題。也許你正在試圖找出一種方法來爲動態數據量分配足夠的內存?您可以使用ReDim語句調整經典ASP(VBScript)中的數組大小 - 一旦知道了真實大小,就可以做到這一點。
1
數組分配在連續的內存中。因此,一個10000個元素的數組將佔用一個需要1000個元素的內存的10倍。
您可以從小處開始,根據需要增加陣列數量。過去我使用過這種類來創建可變長度列表類型。
Class List
Dim maItems
Dim mlCount
Public Sub Class_Initialize()
ReDim maItems(8)
mlCount = 0
End Sub
Public Function Add(Item)
If mlCount = UBound(maItems) ReDim Preserve maItems(mlCount * 2)
mlCount = mlCount + 1
maItems(mlCount) = Item
Add = mlCount
End Function
Public Property Get Item(Index)
If Index < 1 Or Index > mlCount Then Error.Raise 9, "List", "Subscript out of Range"
Item = maItems(Index)
End Property
Public Property Get Count()
Count = mlCount
End Property
End Class
0
這是一個大數組嗎?
爲什麼不分配它是動態的,然後擴大它的增長?上面的代碼的
<%
Dim myDynArray()
ReDim myDynArray(1)
myDynArray(0) = "Albert Einstein"
myDynArray(1) = "Mother Teresa"
ReDim Preserve myDynArray(3)
myDynArray(2) = "Bill Gates"
myDynArray(3) = "Martin Luther King Jr."
For Each item In myDynArray
Response.Write(item & "<br />")
Next
%>
輸出是
Albert Einstein Mother Teresa Bill Gates Martin Luther King Jr.
0
我一點地加入安東尼W¯¯瓊斯的代碼,所以它返回與只有相關元件的正確大小的陣列(ToArray的())。
Class List
Dim maItems
Dim mlCount
Public Sub Class_Initialize()
ReDim maItems(8)
mlCount = 0
End Sub
Public Function Add(Item)
If mlCount = UBound(maItems) Then ReDim Preserve maItems(mlCount * 2)
maItems(mlCount) = Item
mlCount = mlCount + 1
Add = mlCount
End Function
Public Property Get ToArray()
ReDim Result(Params.Count-1)
Dim i
For i = 0 to Params.Count-1
Result(i) = Params.maItems(i)
Next
ToArray = Result
End Property
Public Property Get Item(Index)
If Index < 1 Or Index > mlCount Then Error.Raise 9, "List", "Subscript out of Range"
Item = maItems(Index)
End Property
Public Property Get Count()
Count = mlCount
End Property
End Class
相關問題
- 1. Multi-Dim Array to 1D - 讓它與protobuf一起使用
- 2. 沒有經典的VBScript /經典的ASP型Dim語句
- 3. Dim c as MyClass&Dim c as New MyClass
- 4. Sidenav materializecss window dim
- 5. Dim vs Private/Public
- 6. Redim沒有Dim?
- 7. Dim/Hide leaflet.js
- 8. ImageMapster - dim image
- 9. UIModalPresentationFormSheet,dim is missing
- 10. Dim WithEvents主題
- 11. Dim Screen Android Firemonkey
- 12. Dim iPhone screen
- 13. 3-dim putty(ssh)
- 14. VB.NET Dim vs. New
- 15. ValueError:形狀(56,1)和(56,2)未對齊:1(dim 1)!= 56(dim 0)
- 16. ValueError:形狀(6,108)和(36,)未對齊:108(dim 1)!= 36(dim 0)
- 17. 如何區分具有相同數量的1-dim數組和多dim數組?
- 18. Python和numpy:逐行減去1-dim數組中的2-dim數組
- 19. Swift 3 Popover Dim Background
- 20. Dim a Window from Variable
- 21. Dim Blah as New GeckoWebBrowser
- 22. 2-dim結構表
- 23. Array(Variant)or Array(String)
- 24. 行爲差異Dim oDialog1 as Dialog1 = New Dialog1 VS Dim oDialog1 as Dialog1 = Dialog1
- 25. 從兩個2-dim矩陣創建3-dim矩陣
- 26. 是「dim x()as byte」相當於「dim x as byte()」?
- 27. 從Array
- 28. Numpy normalize multi dim(> = 3)數組
- 29. C++ glfw macosx dim screen vs f1
- 30. VBA到C#中:Dim X
我認爲上述代碼應改爲: 昏暗maItems 昏暗mlCount 公用Sub Class_Initialize() 使用ReDim maItems(8) mlCount = 0 結束子 – PropellerHead 2009-09-23 12:05:11
@PropellerHead:好斑點。我現在大部分時間都花在C#上。 ;) – AnthonyWJones 2009-09-23 14:13:41