Memory
management
Memory Layout of a C
program
●
TEXT
●
Initialized Data
●
Uninitialized Data
●
Stack
●
Heap
Memory Layout
●
When a program is executed, the Operating
System provides a chunk of memory for the
program to use.
●
TEXT, Initialized data, Uninitialized Data and
Stack have fixed sizes
●
The heap size can be dynamically adjusted
through system calls.
TEXT
●
This is where the compiled binary code of
your program is stored
Compiler
This will get loaded
into the TEXT portion
Initialized data
●
Contains global and static variables that
have been initialized by the programmer
Uninitialized data
●
Contains global and static variables that
have not been initialized by the programmer
Stack
●
Used for storing local variables and function
management.
●
Stack size is limited, you can fill the stack upto
the limit (a stack overflow will occur if you try to
exceed this limit)
●
Stack is last-in first-out (that’s why it’s called a
stack)
Stack
●
What can we store in the stack?
●
Primitive data types
- int, float, char
●
Pointers
- int*, char*
●
Fixed size arrays
●
Fixed size structs
Heap
●
Heap size is virtually unlilmited. When you run
out of heap size, you can request more memory
from the Operating system.
●
Heap can be used to store large amounts of
data
●
Store something in heap, then store a pointer to
that data in the stack.
Heap
●
What can we store in the heap? (anything)
●
Integers, Floats, chars
●
Arrays, Linked lists
Heap
●
Think of heap as a lecture hall
●
There are rows and columns of chairs
●
Some people sit in groups
●
Some people sit alone
●
There can be a lot of empty seats
Example
Pointers in c
●
Pass a copy of the value
●
Pass a pointer to the value
●
Pass a pointer to a pointer
Example
Example
Example

More Related Content

PDF
PPT
Linux memorymanagement
PPTX
C MEMORY MODEL​.pptx
PPTX
C MEMORY MODEL​.pptx
PPT
Introduction to pointers and memory management in C
PPT
C language
PPT
79744777- FULL AND DETAILED LEVEL OF Pointers-in-c-Presentation.ppt
PPTX
Linux memorymanagement
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptx
Introduction to pointers and memory management in C
C language
79744777- FULL AND DETAILED LEVEL OF Pointers-in-c-Presentation.ppt

Similar to Memory Management in C, and concepts related to memory management (20)

PPT
Ctutorial-Pointers 1.ppt
PPT
C Programming Tutorial - Pointer Concepts
PPT
Ctutorial-Pointers FULL AND DETAILED LEVEL OF EXPLANATION
PPT
C language
PDF
dynamic-allocation.pdf
PPTX
Memory management of datatypes
PDF
C Interview Questions and Answers by Scholarhat
PPTX
How c++ stored in ram
PDF
Memory Management for C and C++ _ language
PPT
ch08.ppt
PPTX
Memory Management.pptx
PPS
Clanguage
DOCX
DS UNIT3_LINKED LISTS.docx
PPTX
Top Programming Training Centre in Jalandhar
PPTX
Top Programming Training Centre in Jalandhar
PDF
See through C
PPSX
Programming in C [Module One]
PDF
C for Java programmers (part 2)
PDF
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Ctutorial-Pointers 1.ppt
C Programming Tutorial - Pointer Concepts
Ctutorial-Pointers FULL AND DETAILED LEVEL OF EXPLANATION
C language
dynamic-allocation.pdf
Memory management of datatypes
C Interview Questions and Answers by Scholarhat
How c++ stored in ram
Memory Management for C and C++ _ language
ch08.ppt
Memory Management.pptx
Clanguage
DS UNIT3_LINKED LISTS.docx
Top Programming Training Centre in Jalandhar
Top Programming Training Centre in Jalandhar
See through C
Programming in C [Module One]
C for Java programmers (part 2)
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Ad

More from Suhas Disanayake (6)

PDF
Boolean logic and Floating point arithmetic MCQ questoins discussion
PDF
Design Patterns in Object Oriented Design
PDF
Basic Concepts of Python, MCQ question Discussion
PDF
Basics of Computer Architecture and Von Neumann Architecture
PDF
Object Oriented Design and Concepts related to Object Oriented Programming
PDF
Exceptions in Java and Exception Handling
Boolean logic and Floating point arithmetic MCQ questoins discussion
Design Patterns in Object Oriented Design
Basic Concepts of Python, MCQ question Discussion
Basics of Computer Architecture and Von Neumann Architecture
Object Oriented Design and Concepts related to Object Oriented Programming
Exceptions in Java and Exception Handling
Ad

Recently uploaded (20)

PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
advance database management system book.pdf
PDF
HVAC Specification 2024 according to central public works department
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
IGGE1 Understanding the Self1234567891011
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
20th Century Theater, Methods, History.pptx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
Computer Architecture Input Output Memory.pptx
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Complications of Minimal Access-Surgery.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Paper A Mock Exam 9_ Attempt review.pdf.
Hazard Identification & Risk Assessment .pdf
History, Philosophy and sociology of education (1).pptx
Unit 4 Computer Architecture Multicore Processor.pptx
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Environmental Education MCQ BD2EE - Share Source.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
advance database management system book.pdf
HVAC Specification 2024 according to central public works department
Virtual and Augmented Reality in Current Scenario
IGGE1 Understanding the Self1234567891011
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
20th Century Theater, Methods, History.pptx
B.Sc. DS Unit 2 Software Engineering.pptx
FORM 1 BIOLOGY MIND MAPS and their schemes
Computer Architecture Input Output Memory.pptx
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Complications of Minimal Access-Surgery.pdf

Memory Management in C, and concepts related to memory management

  • 2. Memory Layout of a C program ● TEXT ● Initialized Data ● Uninitialized Data ● Stack ● Heap
  • 3. Memory Layout ● When a program is executed, the Operating System provides a chunk of memory for the program to use. ● TEXT, Initialized data, Uninitialized Data and Stack have fixed sizes ● The heap size can be dynamically adjusted through system calls.
  • 4. TEXT ● This is where the compiled binary code of your program is stored Compiler This will get loaded into the TEXT portion
  • 5. Initialized data ● Contains global and static variables that have been initialized by the programmer
  • 6. Uninitialized data ● Contains global and static variables that have not been initialized by the programmer
  • 7. Stack ● Used for storing local variables and function management. ● Stack size is limited, you can fill the stack upto the limit (a stack overflow will occur if you try to exceed this limit) ● Stack is last-in first-out (that’s why it’s called a stack)
  • 8. Stack ● What can we store in the stack? ● Primitive data types - int, float, char ● Pointers - int*, char* ● Fixed size arrays ● Fixed size structs
  • 9. Heap ● Heap size is virtually unlilmited. When you run out of heap size, you can request more memory from the Operating system. ● Heap can be used to store large amounts of data ● Store something in heap, then store a pointer to that data in the stack.
  • 10. Heap ● What can we store in the heap? (anything) ● Integers, Floats, chars ● Arrays, Linked lists
  • 11. Heap ● Think of heap as a lecture hall ● There are rows and columns of chairs ● Some people sit in groups ● Some people sit alone ● There can be a lot of empty seats
  • 13. Pointers in c ● Pass a copy of the value ● Pass a pointer to the value ● Pass a pointer to a pointer