Click here to Skip to main content
15,887,083 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: How to add a single item to an array Pin
PIEBALDconsult24-Jan-18 14:23
mvePIEBALDconsult24-Jan-18 14:23 
GeneralRe: How to add a single item to an array Pin
Eddy Vluggen27-Jan-18 11:19
professionalEddy Vluggen27-Jan-18 11:19 
GeneralRe: How to add a single item to an array Pin
Jon McKee27-Jan-18 17:35
professionalJon McKee27-Jan-18 17:35 
GeneralRe: How to add a single item to an array Pin
jsc4225-Jan-18 22:48
professionaljsc4225-Jan-18 22:48 
GeneralRe: How to add a single item to an array Pin
MikeTheFid29-Jan-18 3:33
MikeTheFid29-Jan-18 3:33 
GeneralRe: How to add a single item to an array Pin
englebart29-Jan-18 4:01
professionalenglebart29-Jan-18 4:01 
GeneralRe: How to add a single item to an array Pin
Mark S. Finn29-Jan-18 5:20
professionalMark S. Finn29-Jan-18 5:20 
GeneralRe: How to add a single item to an array Pin
uoods29-Jan-18 6:45
uoods29-Jan-18 6:45 
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.
GeneralRe: How to add a single item to an array Pin
Stefan_Lang31-Jan-18 21:06
Stefan_Lang31-Jan-18 21:06 
GeneralRe: How to add a single item to an array Pin
Member 1156133529-Jan-18 17:47
Member 1156133529-Jan-18 17:47 
GeneralRe: How to add a single item to an array Pin
#realJSOP16-Feb-18 7:00
mve#realJSOP16-Feb-18 7:00 
GeneralGenuine Message on r/compsci (now deleted) Pin
Rob Grainger10-Jan-18 1:51
Rob Grainger10-Jan-18 1:51 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
MarkTJohnson10-Jan-18 3:16
professionalMarkTJohnson10-Jan-18 3:16 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
OriginalGriff10-Jan-18 3:53
mveOriginalGriff10-Jan-18 3:53 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
Wastedtalent10-Jan-18 4:35
professionalWastedtalent10-Jan-18 4:35 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
GuyThiebaut11-Jan-18 21:34
professionalGuyThiebaut11-Jan-18 21:34 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
Richard Deeming12-Jan-18 2:05
mveRichard Deeming12-Jan-18 2:05 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
Jon McKee27-Jan-18 17:38
professionalJon McKee27-Jan-18 17:38 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
Brisingr Aerowing14-Jan-18 23:38
professionalBrisingr Aerowing14-Jan-18 23:38 
GeneralRe: Genuine Message on r/compsci (now deleted) Pin
Hooga Booga29-Jan-18 3:40
Hooga Booga29-Jan-18 3:40 
RantI failed to predict this one...new csv format Pin
kmoorevs1-Dec-17 10:56
kmoorevs1-Dec-17 10:56 
GeneralRe: I failed to predict this one...new csv format Pin
PIEBALDconsult1-Dec-17 12:47
mvePIEBALDconsult1-Dec-17 12:47 
GeneralRe: I failed to predict this one...new csv format Pin
Rob Grainger10-Dec-17 12:36
Rob Grainger10-Dec-17 12:36 
GeneralRe: I failed to predict this one...new csv format Pin
PIEBALDconsult10-Dec-17 12:58
mvePIEBALDconsult10-Dec-17 12:58 
PraiseRe: I failed to predict this one...new csv format Pin
kmoorevs11-Dec-17 9:02
kmoorevs11-Dec-17 9:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.