Click here to Skip to main content
15,892,537 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: C# - Arrays vs Arraylist Pin
hamityildirim15-Oct-08 18:26
hamityildirim15-Oct-08 18:26 
GeneralRe: C# - Arrays vs Arraylist Pin
leppie15-Oct-08 20:18
leppie15-Oct-08 20:18 
GeneralRe: C# - Arrays vs Arraylist Pin
snorkie16-Oct-08 4:35
professionalsnorkie16-Oct-08 4:35 
GeneralRe: C# - Arrays vs Arraylist Pin
Eddy Vluggen22-Oct-08 23:32
professionalEddy Vluggen22-Oct-08 23:32 
JokeRe: C# - Arrays vs Arraylist Pin
megaadam17-Oct-08 2:50
professionalmegaadam17-Oct-08 2:50 
GeneralRe: C# - Arrays vs Arraylist Pin
Redwan Albougha17-Oct-08 15:45
Redwan Albougha17-Oct-08 15:45 
GeneralRe: C# - Arrays vs Arraylist Pin
Paul Conrad17-Oct-08 18:20
professionalPaul Conrad17-Oct-08 18:20 
GeneralRe: C# - Arrays vs Arraylist Pin
Mike Dimmick19-Oct-08 1:34
Mike Dimmick19-Oct-08 1:34 
I don't know what he was smoking, an ArrayList or generic List<> simply manage a single array under the covers, resizing it as required. You need to be able to allocate a contiguous array to hold all the elements.

Maybe he was confused with C++'s deque, which does generally manage multiple array segments.

.NET has no concept of near or far heaps. It does have a Large Object Heap which is used for large allocations; the belief is that large objects will generally be kept around so the Large Object Heap is swept at the same time as a Generation 2 garbage collection. This can keep otherwise short-lifed objects around. The choice of regular or Large Object heaps is only down to the size of the objects themselves: a 1MB array or a 1MB capacity for an ArrayList makes no difference.

One distinction between ArrayList and, say, an int[] is that ArrayList manages an object[], which causes value types to be boxed when added to the collection and unboxed when they're used. In contrast the generic List<int> manages an int[], but that means an actual copy of the implementation is required, and generated by the JIT, for every different value type that is used as a type parameter. The same implementation is used for all reference types.

string is, of course, a reference type.

Arrays themselves are reference types so there should be no difference in passing an array or an ArrayList between methods. He probably managed to measure JIT time and got an incorrect answer, or simply got a page fault or a reschedule in the middle of a measurement.

It can be convenient to build something in an ArrayList then copy to an array when you don't know how big the array needs to be at the outset, and you can't change the rest of the code to use an ArrayList instead. If you wrote your own, you'd probably end up mirroring the code in ArrayList itself. Many .NET controls and methods support binding to an IList to give you some flexibility in the container you use.

"Multithreading is just one damn thing after, before, or simultaneous with another." - Andrei Alexandrescu

GeneralRe: C# - Arrays vs Arraylist Pin
hamityildirim10-Nov-08 0:24
hamityildirim10-Nov-08 0:24 
GeneralRe: C# - Arrays vs Arraylist [modified] Pin
Megidolaon23-Feb-09 0:32
Megidolaon23-Feb-09 0:32 
Generalstdcall_api Pin
thoru8-Oct-08 2:11
thoru8-Oct-08 2:11 
GeneralRe: stdcall_api Pin
PIEBALDconsult8-Oct-08 3:15
mvePIEBALDconsult8-Oct-08 3:15 
GeneralRe: stdcall_api Pin
Rob Grainger10-Oct-08 0:53
Rob Grainger10-Oct-08 0:53 
GeneralRe: stdcall_api Pin
PIEBALDconsult10-Oct-08 8:47
mvePIEBALDconsult10-Oct-08 8:47 
AnswerRe: stdcall_api Pin
Redwan Albougha18-Oct-08 11:05
Redwan Albougha18-Oct-08 11:05 
GeneralA horror in release code Pin
Scott Barbour3-Oct-08 10:04
Scott Barbour3-Oct-08 10:04 
GeneralRe: A horror in release code Pin
Jason Lepack (LeppyR64)3-Oct-08 10:23
Jason Lepack (LeppyR64)3-Oct-08 10:23 
GeneralRe: A horror in release code Pin
Scott Barbour3-Oct-08 10:31
Scott Barbour3-Oct-08 10:31 
GeneralRe: A horror in release code Pin
leppie3-Oct-08 23:12
leppie3-Oct-08 23:12 
GeneralRe: A horror in release code Pin
PIEBALDconsult4-Oct-08 6:31
mvePIEBALDconsult4-Oct-08 6:31 
GeneralRe: A horror in release code PinPopular
Steven A. Lowe10-Oct-08 4:04
Steven A. Lowe10-Oct-08 4:04 
GeneralRe: A horror in release code Pin
Graham Bradshaw4-Oct-08 9:05
Graham Bradshaw4-Oct-08 9:05 
GeneralRe: A horror in release code Pin
Paul Conrad5-Oct-08 18:51
professionalPaul Conrad5-Oct-08 18:51 
GeneralRe: A horror in release code Pin
Alois Kraus8-Oct-08 22:40
Alois Kraus8-Oct-08 22:40 
Generala minor horror Pin
BillW333-Oct-08 9:23
professionalBillW333-Oct-08 9:23 

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.