Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As I understand it, a "reference" type in C# is roughly analogous to a pointer in C++. If that is the case, I'm trying to figure out if System.Collections.LinkedList really serves any purpose. If I were working in C++, I would not incur the memory overhead of a linked list if my data type was going to be merely a pointer. I believe one of the big selling points of linked lists over arrays is the non-need for consecutive memory. But when dealing with pointers, it's not terribly difficult for modern computers to allocate even very large arrays of pointers. I suppose the need could still be there for a program that had a lot more structs than classes.

Has anyone out there ever used LinkedList? Was it really necessary, or did you just find yourself in that thought pattern if you came from a C/C++ background?
Posted

1 solution

Yes, it perfectly serves a purpose where this criteria is important: fast insert/remove operation, with performance not depending on the length of the list.

Your speculations on the value of linked list are hardly correct. First, from the standpoint of the algorithms in question, there are no essential difference between managed references and pointers. The difference between them (the ability of referenced objects to relocate in physical memory) is absolutely transparent for the algorithm. Also, when it comes to the linked list or a regular list, there is no so big difference between structures and classes. Remember that structure members can be reference types. However, the idea about benefits of linked list for some special case is correct: this is the case when the instances of structures are big and the members are predominantly reference type, recursively — in this case the need for big consecutive memory can be relaxed with the linked lists. But this is not the only benefit, and not the main benefit of linked lists.

—SA
 
Share this answer
 
Comments
Xpnctoc 2-May-12 16:42pm    
Great point. I guess my question is the product of the emphasis when I was in college almost 20 years ago (yikes!). Computer memory was much more scarce then, and my classes emphasized the memory savings. The mechanics of insert/remove were presented more as a necessary evil rather than a performance gain.
Sergey Alexandrovich Kryukov 2-May-12 16:47pm    
Thank you for understanding.
I don't know who looked at that as at evil; maybe this is just the effect of mandatory discipline. I leaned almost all by myself and found those list-like pointer operations pretty exciting... even though it was on 640K of RAM.

Good luck, call again.
--SA
VJ Reddy 4-May-12 13:06pm    
Nice explanation. fast insert/remove operation is a good point. 5!
Sergey Alexandrovich Kryukov 4-May-12 13:08pm    
Thank you, VJ.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900