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. 經典ASP DIM可變嗎?
- 2. 沒有經典的VBScript /經典的ASP型Dim語句
- 3. Dim c as MyClass&Dim c as New MyClass
- 4. UIModalPresentationFormSheet,dim is missing
- 5. Dim/Hide leaflet.js
- 6. Dim WithEvents主題
- 7. VB.NET Dim vs. New
- 8. Dim Screen Android Firemonkey
- 9. Dim iPhone screen
- 10. 如何區分具有相同數量的1-dim數組和多dim數組?
- 11. ValueError:形狀(6,108)和(36,)未對齊:108(dim 1)!= 36(dim 0)
- 12. Python和numpy:逐行減去1-dim數組中的2-dim數組
- 13. Swift 3 Popover Dim Background
- 14. 2-dim結構表
- 15. 行爲差異Dim oDialog1 as Dialog1 = New Dialog1 VS Dim oDialog1 as Dialog1 = Dialog1
- 16. 從兩個2-dim矩陣創建3-dim矩陣
- 17. 從Array
- 18. Numpy normalize multi dim(> = 3)數組
- 19. Dim and Private的區別
- 20. 模式對話框dim
- 21. VBA到C#中:Dim X
- 22. C++ glfw macosx dim screen vs f1
- 23. 初始化Scala中的2-dim數組
- 24. String Array事情!
- 25. Php array _push not push another array push
- 26. Select array with array
- 27. Rank Array Array
- 28. Convert Array to DayOfWeek
- 29. vba variant array bug
- 30. Array in Array in JSON
我認爲上述代碼應改爲: 昏暗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