Dynamic memory allocation

Posted on 2003-02-28
Medium Priority
Last Modified: 2010-04-17
What is the purpose of using Linked Lists?
Can't an array of a user defined structure be used instead of a Linked List?
Question by:Mert_Sedef
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 46

Accepted Solution

Kent Olsen earned 400 total points
ID: 8043811

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.  :)


Author Comment

ID: 8044257
Thank you very much! :)
LVL 46

Expert Comment

by:Kent Olsen
ID: 8044297
Glad to assist.


Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question