Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Dynamic memory allocation

Posted on 2003-02-28
3
Medium Priority
?
204 Views
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?
0
Comment
Question by:Mert_Sedef
  • 2
3 Comments
 
LVL 46

Accepted Solution

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

Kdo
0
 

Author Comment

by:Mert_Sedef
ID: 8044257
Thank you very much! :)
Mert...
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8044297
Glad to assist.

Kdo
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
Starting up a Project
Loops Section Overview

578 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