Adding a single item to an array causes the entire array to be reallocated and copied. Simply put, the only array that can add an item is a linked list. Some of the suggested solutions use a different datatype List<> to create a copy of the original array, use its built in function ".Add" to insert an item, then creating a brand new array containing all the items. If the array needs to change again, then a whole new copy will be created in memory. This is all okay because it works, but it's not ideal. Copying a large array over and over only to add a single item at the end repeatedly will consume more CPU cycles (electricity and time) than necessary. Do what you have to to make it work, but then search for a better approach and adopt that when you find it. The highest performance method would be to use a linked list. In C++, linked lists can be very fast & cheap, but there are also some implementations in C#. The List<> object is a very nice implementation of a linked list, but there is also a LinkedList<> object that is optimized for adding items anywhere within the object.
uoods
Posts
-
How to add a single item to an array -
Datagrid edit command textbox referenceI think you should break your statements into different parts. Do you feel pressured to stick all those functions on one single line? Doing this will allow you to see the problem more quickly, fix it and move on. This example probably has bugs in it, but try something like this:
If e.CommandName = "Edit" Then
dgAnswers.EditItemIndex = e.Item.ItemIndex
Dim txt as Textbox
txt = CType(dgAnswers.Items(e.Item.ItemIndex).FindControl("txtAnsEdit"),TextBox)
If not isnothing(txt) then
'since you have the object reference assigned to txt, assign the value using this alias
txt.Text = "tada"
Else
'Could not find the textbox.
End if
End If -
How much RAM you have?You could do this even in Windows NT 4.0, but in my experience, you will have occasional stability problems. Every so often, some system process associated with the kernel will expect that there is a swap file and try to reference it. When it happens, it results in a kernel crash (bsod). I'm sure there are some legacy code places (bugs) in Windows that still expect a swap file.