Dynamic memory allocation

What is the purpose of using Linked Lists?
Can't an array of a user defined structure be used instead of a Linked List?
Mert_SedefAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenData Warehouse Architect / DBACommented:

For many, many applications linked lists are the only practical way to manage memory.  They utilize memory in a way that the program doesn't have to reserve huge memory blocks "just in case" the object be put in memory is very large.

Your C program's heap is actually a linked list.  When you request memory with malloc(), the memory management routine passes you an address that is the start of YOUR buffer.  But the memory manager has to know that it "gave" you that chuck of memory.  It does that by reserving a piece of memory just a little bit larger than you requested (usually 8 to 16 bytes).  In this "extra memory" it stores the length of the block, and a pointer.

This pointer is part of a linked list structure.  The blocks that you request from the heap are organized as a linked list.  The C libraries certainly couldn't reorganize all of memory into a single array every time you did a malloc() or free() -- all of your pointers would be corrupted.


There are thousands of applications for linked lists.  Management of the heap just happens to be one of the most common ones -- and one of the most hidden.  :)

Kdo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mert_SedefAuthor Commented:
Thank you very much! :)
Mert...
0
Kent OlsenData Warehouse Architect / DBACommented:
Glad to assist.

Kdo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.