SlideShare uma empresa Scribd logo
1 de 8
Dynamic Memory Allocation and
Linked Lists
Topics
 Dynamic memory allocation

Dynamic Memory Allocation
 The process of allocating memory at run
time is known as dynamic memory
allocation.
 There are some functions for dynamic
memory allocation. These are malloc, calloc,
free and realloc.
Allocating a Block of Memory
 A block of memory may be allocated using
the function malloc. The malloc function
reserves a block of memory of specified size
and returns a pointer of type void. The form-
ptr = (cast-type *)malloc(byte-size);
ptr is a pointer of type cast-type.
 Example:
ptr = (int *) malloc(100*sizeof(int));
Allocating Multiple blocks of Memory
 Calloc is another memory allocation function
that is normally used for request memory
space at run time for storing derived data
types such as array and structures. It
allocates multiple blocks of storage, each of
the same size. The general format-
ptr = (cast-type *)calloc(n,element-size);
Releasing the used space & Altering the size
 free function can be used to release the
used space. The format is-
free(ptr);
 We can change the memory size already
allocated with the help of the function
realloc.
ptr = realloc(ptr, newsize);
Concepts of Linked List
 A linked list is one kind of list whose order is given
by links from one item to the next.
 Each structure of the list is called a node and
consists of two fields, one containing the item and
the other containing the address of the next item in
the list.
 A linked list is therefore a collection of structures
ordered not by their physical placement in memory
but by logical links that are stored as part of the
data in the structure itself. The link is in the form of
a pointer to another structure of the same type.
Continue…
 The structure is represented as:
struct node
{
int item;
struct node *next;
};
Advantage of Linked List
 Advantages:
1. Linked list can grow or shrink in size
during the execution of a program.
2. It does not waste memory space.
3. It provides flexibility in allowing the items
to be rearranged efficiently.
 Limitation:
1. The access of any arbitrary item is little
cumbersome and time consuming.
2. It will use more storage than an array with
the same number of items as it has link field.

Mais conteúdo relacionado

Mais procurados

Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introductionMandeep Singh
 
Union In language C
Union In language CUnion In language C
Union In language CRavi Singh
 
Str
StrStr
StrAcad
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structureshaibal sharif
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation ashu awais
 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structureRajendran
 
Over view of data structures
Over view of data structuresOver view of data structures
Over view of data structuresNagajothiN1
 
Union in c language
Union  in c languageUnion  in c language
Union in c languagetanmaymodi4
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structuresunilchute1
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 

Mais procurados (17)

Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Structure in c
Structure in cStructure in c
Structure in c
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introduction
 
Union In language C
Union In language CUnion In language C
Union In language C
 
Str
StrStr
Str
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Week 4 dq 4
Week 4 dq 4Week 4 dq 4
Week 4 dq 4
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structure
 
Over view of data structures
Over view of data structuresOver view of data structures
Over view of data structures
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
Data structures
Data structuresData structures
Data structures
 
Data strucer
Data strucerData strucer
Data strucer
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Data struters
Data strutersData struters
Data struters
 
Data structure
Data  structureData  structure
Data structure
 

Destaque

04 ds and algorithm session_05
04 ds and algorithm session_0504 ds and algorithm session_05
04 ds and algorithm session_05Niit Care
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
07 ds and algorithm session_10
07 ds and algorithm session_1007 ds and algorithm session_10
07 ds and algorithm session_10Niit Care
 
05 ds and algorithm session_07
05 ds and algorithm session_0705 ds and algorithm session_07
05 ds and algorithm session_07Niit Care
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structuresWipro
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsDr Sandeep Kumar Poonia
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matricesZain Zafar
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Adam Mukharil Bachtiar
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Top10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing WorldTop10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing WorldMahindra Rise
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 

Destaque (20)

Linked list
Linked listLinked list
Linked list
 
04 ds and algorithm session_05
04 ds and algorithm session_0504 ds and algorithm session_05
04 ds and algorithm session_05
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
07 ds and algorithm session_10
07 ds and algorithm session_1007 ds and algorithm session_10
07 ds and algorithm session_10
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
 
05 ds and algorithm session_07
05 ds and algorithm session_0705 ds and algorithm session_07
05 ds and algorithm session_07
 
Linked Lists
Linked ListsLinked Lists
Linked Lists
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structures
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matrices
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
linked list
linked list linked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Top10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing WorldTop10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing World
 
Data Structure
Data StructureData Structure
Data Structure
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 

Semelhante a Chap 13(dynamic memory allocation)

DS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxDS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxprakashvs7
 
Data Structures_Introduction
Data Structures_IntroductionData Structures_Introduction
Data Structures_IntroductionThenmozhiK5
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture NotesFellowBuddy.com
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptxjack881
 
Dma
DmaDma
DmaAcad
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptxMumtaz
 
Chapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.pptChapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.pptNORSHADILAAHMADBADEL
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxGIRISHKUMARBC1
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programmingTOPS Technologies
 
Collectn framework copy
Collectn framework   copyCollectn framework   copy
Collectn framework copycharan kumar
 
Collectn framework
Collectn frameworkCollectn framework
Collectn frameworkcharan kumar
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationMoniruzzaman _
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++Jeff TUYISHIME
 

Semelhante a Chap 13(dynamic memory allocation) (20)

DS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxDS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptx
 
Data Structures_Introduction
Data Structures_IntroductionData Structures_Introduction
Data Structures_Introduction
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture Notes
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
 
Dma
DmaDma
Dma
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptx
 
Chapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.pptChapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.ppt
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptx
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
06 linked list
06 linked list06 linked list
06 linked list
 
Collectn framework copy
Collectn framework   copyCollectn framework   copy
Collectn framework copy
 
Collectn framework
Collectn frameworkCollectn framework
Collectn framework
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
Linked list
Linked listLinked list
Linked list
 
Data structures
Data structuresData structures
Data structures
 

Mais de Bangabandhu Sheikh Mujibur Rahman Science and Technology University

Mais de Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Antenna (2)
Antenna (2)Antenna (2)
Antenna (2)
 
Voltage suppler..
Voltage suppler..Voltage suppler..
Voltage suppler..
 
Number system
Number systemNumber system
Number system
 
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 12(files)
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 5(decision making-branching)
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Computer hardware ppt1
Computer hardware ppt1Computer hardware ppt1
Computer hardware ppt1
 
# Operating system
# Operating system# Operating system
# Operating system
 
Magnetism 3
Magnetism 3Magnetism 3
Magnetism 3
 
Magnetism 2
Magnetism 2Magnetism 2
Magnetism 2
 
2. sinusoidal waves
2. sinusoidal waves2. sinusoidal waves
2. sinusoidal waves
 
Magnetism 1
Magnetism 1Magnetism 1
Magnetism 1
 
1. rc rl-rlc
1. rc rl-rlc1. rc rl-rlc
1. rc rl-rlc
 

Último

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 

Último (20)

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 

Chap 13(dynamic memory allocation)

  • 1. Dynamic Memory Allocation and Linked Lists Topics  Dynamic memory allocation 
  • 2. Dynamic Memory Allocation  The process of allocating memory at run time is known as dynamic memory allocation.  There are some functions for dynamic memory allocation. These are malloc, calloc, free and realloc.
  • 3. Allocating a Block of Memory  A block of memory may be allocated using the function malloc. The malloc function reserves a block of memory of specified size and returns a pointer of type void. The form- ptr = (cast-type *)malloc(byte-size); ptr is a pointer of type cast-type.  Example: ptr = (int *) malloc(100*sizeof(int));
  • 4. Allocating Multiple blocks of Memory  Calloc is another memory allocation function that is normally used for request memory space at run time for storing derived data types such as array and structures. It allocates multiple blocks of storage, each of the same size. The general format- ptr = (cast-type *)calloc(n,element-size);
  • 5. Releasing the used space & Altering the size  free function can be used to release the used space. The format is- free(ptr);  We can change the memory size already allocated with the help of the function realloc. ptr = realloc(ptr, newsize);
  • 6. Concepts of Linked List  A linked list is one kind of list whose order is given by links from one item to the next.  Each structure of the list is called a node and consists of two fields, one containing the item and the other containing the address of the next item in the list.  A linked list is therefore a collection of structures ordered not by their physical placement in memory but by logical links that are stored as part of the data in the structure itself. The link is in the form of a pointer to another structure of the same type.
  • 7. Continue…  The structure is represented as: struct node { int item; struct node *next; };
  • 8. Advantage of Linked List  Advantages: 1. Linked list can grow or shrink in size during the execution of a program. 2. It does not waste memory space. 3. It provides flexibility in allowing the items to be rearranged efficiently.  Limitation: 1. The access of any arbitrary item is little cumbersome and time consuming. 2. It will use more storage than an array with the same number of items as it has link field.