SlideShare a Scribd company logo
1 of 32
Memory Management
To cover
•Overview.
•Strategies for Allocating Variables to Memory.
•Design Patterns for Limited Memory.
•Memory Management in Mobile Java.
•Symbian OS Memory Management.
Overview
•Memory management is different from managing
some other resources
•Tangling everywhere
•Mobile devices memory is a critical resource
- cost of the device low
- running programs are competing for it
•Explicitly allocate memory in many imperative
languages, such as C and C++
•Memory consumption in mobile devices a cross-
cutting problem
Strategies for Allocating Variables to
Memory
•Stack and the heap are principle memory areas
•Run-time infrastructure and the programmer are
responsible for their management
•In heap, sharing of data is easy and natural
•Stack-based variables references should use with
care
- stack increases and decreases, and may overwrite
referred data
•Statically allocated to a permanent location or
dynamically allocated from stack or heap
Static Allocation
•Throughout program life variable remains allocated
•Memory locations used by it cannot be deallocated.
int * pointer_to_static()
{
static int x;
return &x;
}
•Singleton pattern
- a single instance (or a few instances) of a class, and
make it known to all subsystems.
Stack
•Transient objects
- Those that live only a limited period of time, are to be
stored in the stack.
int * pointer_to_int()
{
int x;
return &x;
}
•Returned reference points to a location in the
memory
•Potentially overwritten by any later functions that will
be called by the program
Stack Limitations
•Hard-to-repeat errors and complex debugging
tasks.
•Stack could exhaust when data is accidentally
copied by making a method or function call
•Better to allocate big objects from the heap
•to ensure that the object is not accidentally modified
via a
reference, const definition can be used where
applicable
Heap
•All data structures whose size or structure can be
altered dynamically must be allocated to the heap.
•Since, unknown structures are impossible to
reserve enough space from the stack.
•Global object, should be allocated memory from
heap.
•garbage collection is a responsibility of the caller if
there is no automation
•Heap can be slower than using the stack
Design Patterns for Limited Memory
•Design should be based on the most adequate data
structure, which offers the right operations.
- Use singly link list instead double if it is enough.
•Better performance if support can be gained from
cache.
•Design patterns created for help in designing small
memory software.
•Linear Data Structures:
- Where different elements are located next to each other
in the memory.
- For instance, implementations of lists and tree-like data
structures.
- Linear data structures are generally better for memory
management than non-linear ones.
Design Patterns for Limited Memory
•Less fragmentation:
- Linear data structures occupy memory place from one
location.
- whereas non-linear ones can be located in different places.
- Obviously, the former results in less possibility for
fragmentation.
•Less searching overhead:
- Reserving a linear block of memory for several items only
takes one search for a suitable memory element in the run-
time environment
- whereas non-linear structures require one request for memory
per allocated element.
- Combined with a design where one object allocates a number
of child objects, this may also lead to a serious performance
problem.
Design Patterns for Limited Memory
•Design-time management:
- Linear blocks are easier to manage at design time, as
fewer reservations are made.
- This usually leads to cleaner designs.
•Monitoring:
- Addressing can be performed in a monitored fashion,
because it is possible to check that the used index refers
to a legal object.
• Cache improvement:
- using linear data structures, it is more likely that the next
data element is already in cache
Design Patterns for Limited Memory
• Index uses less memory:
- An absolute reference to an object usually consumes 32
bits,
- whereas by allocating objects to a vector of 256 objects,
assuming that this is the upper limit of objects, an index
of only 8 bits can be used.
- Furthermore, it is possible to check that there will be no
invalid indexing.
Design Patterns for Limited Memory
•Basic Design Decisions:
•Allocate all memory at the beginning of a program.
- Reserving all the resources is particularly attractive when
the most important or mandatory features like emergency
calls
•Allocate memory for several items, even if you only
need one.
- a number of objects is reserved with one allocation
request.
- less complex structure in the memory.
- fewer memory allocations, and cache use is improved.
•Use standard allocation sizes.
- easy to reuse a deallocated area in the memory.
- fragmentation of memory can be prevented.
Design Patterns for Limited Memory
•Reuse objects.
- programmer actively participates in the process of
selecting object construction and destruction policy
• Release early, allocate late.
- objects occupying a large amount of memory are
deallocated before allocating new objects.
•Use permanent storage or ROM when applicable.
- in case of battery removal from the device, unsaved data
will be lost
- save all data to permanent storage as soon as possible.
•Avoid recursion.
- size of a single stack frame in KVM is 28 bytes (7×4 bytes).
- functions calling themselves recursively can end up using a
lot of stack
Design Patterns for Limited Memory
•Data Packing
- way to reduce memory consumption.
•Consider word alignment.
struct S {
char c1; // Actually a boolean.
int i;
char c2;
};
- three words are required
- By changing the data structure to
struct S {
char c1; // Actually a boolean.
char c2;
int i;
};
Design Patterns for Limited Memory
- c1 and c2 fit in the same word.
- improvement can be gained by using only one bit
for the Boolean value, assuming that there would
be some other data to include in the saved bits.
Design Patterns for Limited Memory
•Use compression with care.
- May impair performance while compressing data or
opening files
- three different compression techniques:
- Table compression
• also referred to as nibble coding or Huffman coding
• encoding each element of data in a variable number of bits
• so that the more common elements require fewer bits.
- Difference coding
• representing sequences of data according to the differences
between them.
- Adaptive compression
• is based on algorithms that analyze the data to be compressed
Design Patterns for Limited Memory
•Use efficient resource storage format.
- ensure that images, sounds, and movies are stored in the
most efficient way
- possible to save some space by combining many image
files into one image file.
Design Patterns for Limited Memory
•Discussion
- memory management are not problem-free.
- when improving a certain property of software design,
some other part is downgraded or compromised.
•Increased minimal memory usage.
- simplistic implementation.
•Decreased flexibility.
- it is possible that some hardware configurations are
invalidated.
•Downgraded performance.
- Using some form of compression can lead to decreased
memory use
- packing a lot of information into the same memory word
can lead to downgraded performance.
Design Patterns for Limited Memory
•Longer initialization and shutdown sequences
- it is possible to handle some of the operations associated with
memory at the beginning or at the end of the program
- rather than in the middle of the execution, startup and
termination of the program can become slower.
• Potential unintuitiveness in designs
- When an experienced designer composes a design in a
memory-aware fashion,
- some of the decisions can be unintuitive to less experienced
developers.
•Impaired reusability
- The more one addresses particularities of a certain design
problem in the solution,
- the less likely it is that the same solution could be used again
in another context.
Design Patterns for Limited Memory
•To summarize, it is a necessity to balance between
the different requirements addressing the properties
of designs.
Memory Management in Mobile Java
•Code optimization could be error prone
- Such systems running on Virtual Machines
- May cause abstraction leakage
• Motivation
- Despite of managing resources automatically, use appropriate
data structures (garbage collection using DS)
- For instance, implementing a stack of references on a virtual
machine
- The stack is implemented as a vector.
- An index (size) to the vector is used as the stack pointer
- Stack pointer is incremented by one, when a new item is
added.
Public void push(Object e) {
ensureCapacity( ); // Check that slots are available.
elements [size++] = e;
}
- Similarly, when an element is removed from the stack, the
stack pointer is decremented by one.
public Object pop(){
if(size == 0) throw new EmptyStackException();
return elements[--size];
}
- Reference to garbage collection, there can be ‘ghost’
references to objects that are unusable
- but remain valid and accessible in the vector used in the
implementation.
- Such ‘ghosts’ are a result of executing several push and pop
operations.
- The garbage collector is not allowed to deallocate them before
the last reference to them has been erased, and having an
accidental unused reference counts in this respect.
- the problem can be solved by setting vector element to
zero in method pop:
public Object pop() {
if(size == 0) throw new
EmptyStackException();
Object result = elements[--size];
elements[size] = null;
return result;
}
Rules of Thumb for Mobile Java
•Avoid small classes.
- it is better for memory consumption to merge small
classes into bigger ones.
- Usually inner classes contain only little functionality, like a
particular listener of some user action.
- keeping the number of different exceptions as small as
possible.
- For instance, the memory consumption of an application
that was implemented using two different structural
alternatives, shrank to almost half from 14 019 bytes to
7467 bytes when the number of classes was reduced
from 14 to 1 without altering the behavior of the
application (Hartikainen et al. 2006).
•Avoid dependencies.
- one might save memory by removing references
•Select the size when relevant, and manage vector/string
usage.
- whenever possible, by providing the size of the vector instead
of using the default size
•Consider using array versus using vector.
- the difference between array- and vector-based
implementations is relevant both in terms of the number of
objects and used bytes.
- vector effectively need to wrap integers to objects to be able to
store their values
- an implementation where the correct size is given in the
constructor, allocates up to 24% less memory in terms of size.
•Use StringBuffer.
- Concatenating String with the + operator or with the
append
method consumes memory as the virtual machine
needs to create temporary objects.
- Using strings
// String based implementation.
public void useString()
{
String s = "";
for(int i = 0; i < AMOUNT; i++)
{
s = s + "a";
}
}
Using StringBuffer
// StringBuffer based
implementation.
public void
useStringBuffer() {
String s = "";
StringBuffer sb = new
StringBuffer(AMOUNT);
for(int i = 0; i < AMOUNT;
i++) {
sb = sb.append("a");
}
s = sb.toString();
}
•Manage class and object structure.
- Inheritance can sometimes cost memory
- When creating an object of a child class also its parent class
needs to be loaded
- All the variables from the parent are present in a child object
- hierarchy of classes constructed can lead to superfluous
loading and memory consumption.
•Generate less garbage.
- Reusing old objects to avoid making garbage.
•Consider obfuscation.
- majority of the content of a Java library often consists of
metainformation and strings.
- one can reduce footprint by obfuscating the names of public
instance variables and methods, classes, and packages to a
smaller form.
•Handle array initialization.
- Long arrays static initializer can consume a lot of space
- Improved tool support can offer solutions that consume
less memory.
- In practice, the difference only becomes meaningful when
the size of an array is over 1000 (Hartikainen, 2005).

More Related Content

What's hot

Hardware and Software parallelism
Hardware and Software parallelismHardware and Software parallelism
Hardware and Software parallelismprashantdahake
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dosvanamali_vanu
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)Dinesh Modak
 
Virtualize of IO Devices .docx
Virtualize of IO Devices .docxVirtualize of IO Devices .docx
Virtualize of IO Devices .docxkumari36
 
program flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architectureprogram flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architecturePankaj Kumar Jain
 
Context model
Context modelContext model
Context modelUbaid423
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazationSiva Sathya
 
VIRTUALIZATION STRUCTURES TOOLS.docx
VIRTUALIZATION STRUCTURES TOOLS.docxVIRTUALIZATION STRUCTURES TOOLS.docx
VIRTUALIZATION STRUCTURES TOOLS.docxkumari36
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architecturesPooja Dixit
 
cloud computing:Types of virtualization
cloud computing:Types of virtualizationcloud computing:Types of virtualization
cloud computing:Types of virtualizationDr.Neeraj Kumar Pandey
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Meghaj Mallick
 
Architecture of Mobile Computing
Architecture of Mobile ComputingArchitecture of Mobile Computing
Architecture of Mobile ComputingJAINIK PATEL
 
Market oriented Cloud Computing
Market oriented Cloud ComputingMarket oriented Cloud Computing
Market oriented Cloud ComputingJithin Parakka
 

What's hot (20)

Hardware and Software parallelism
Hardware and Software parallelismHardware and Software parallelism
Hardware and Software parallelism
 
Message passing in Distributed Computing Systems
Message passing in Distributed Computing SystemsMessage passing in Distributed Computing Systems
Message passing in Distributed Computing Systems
 
Cloud Reference Model
Cloud Reference ModelCloud Reference Model
Cloud Reference Model
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)
 
Virtualize of IO Devices .docx
Virtualize of IO Devices .docxVirtualize of IO Devices .docx
Virtualize of IO Devices .docx
 
Memory management
Memory managementMemory management
Memory management
 
Cloud Infrastructure Mechanisms
Cloud Infrastructure MechanismsCloud Infrastructure Mechanisms
Cloud Infrastructure Mechanisms
 
program flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architectureprogram flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architecture
 
Context model
Context modelContext model
Context model
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 
Virtualization in cloud computing
Virtualization in cloud computingVirtualization in cloud computing
Virtualization in cloud computing
 
VIRTUALIZATION STRUCTURES TOOLS.docx
VIRTUALIZATION STRUCTURES TOOLS.docxVIRTUALIZATION STRUCTURES TOOLS.docx
VIRTUALIZATION STRUCTURES TOOLS.docx
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architectures
 
cloud computing:Types of virtualization
cloud computing:Types of virtualizationcloud computing:Types of virtualization
cloud computing:Types of virtualization
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
 
Mainframe systems
Mainframe systemsMainframe systems
Mainframe systems
 
Google App Engine ppt
Google App Engine  pptGoogle App Engine  ppt
Google App Engine ppt
 
Architecture of Mobile Computing
Architecture of Mobile ComputingArchitecture of Mobile Computing
Architecture of Mobile Computing
 
Market oriented Cloud Computing
Market oriented Cloud ComputingMarket oriented Cloud Computing
Market oriented Cloud Computing
 

Similar to 4 memory management bb

Scalability Considerations
Scalability ConsiderationsScalability Considerations
Scalability ConsiderationsNavid Malek
 
Heap Memory Management.pptx
Heap Memory Management.pptxHeap Memory Management.pptx
Heap Memory Management.pptxViji B
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in JavaRuben Badaró
 
PAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docxPAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docxImranBhatti58
 
Main MeMory Data Base
Main MeMory Data BaseMain MeMory Data Base
Main MeMory Data BaseSiva Rushi
 
Downscaling: The Achilles heel of Autoscaling Apache Spark Clusters
Downscaling: The Achilles heel of Autoscaling Apache Spark ClustersDownscaling: The Achilles heel of Autoscaling Apache Spark Clusters
Downscaling: The Achilles heel of Autoscaling Apache Spark ClustersDatabricks
 
Internet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IVInternet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IVArti Parab Academics
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephenSteve Feldman
 
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters Ceph Community
 
Scaling up Machine Learning Algorithms for Classification
Scaling up Machine Learning Algorithms for ClassificationScaling up Machine Learning Algorithms for Classification
Scaling up Machine Learning Algorithms for Classificationsmatsus
 
07-MemoryManagement.ppt
07-MemoryManagement.ppt07-MemoryManagement.ppt
07-MemoryManagement.ppthello509579
 
Project Presentation Final
Project Presentation FinalProject Presentation Final
Project Presentation FinalDhritiman Halder
 
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)Lars Marowsky-Brée
 
Training Webinar: Enterprise application performance with distributed caching
Training Webinar: Enterprise application performance with distributed cachingTraining Webinar: Enterprise application performance with distributed caching
Training Webinar: Enterprise application performance with distributed cachingOutSystems
 

Similar to 4 memory management bb (20)

Scalability Considerations
Scalability ConsiderationsScalability Considerations
Scalability Considerations
 
Heap Memory Management.pptx
Heap Memory Management.pptxHeap Memory Management.pptx
Heap Memory Management.pptx
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in Java
 
PAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docxPAGIN AND SEGMENTATION.docx
PAGIN AND SEGMENTATION.docx
 
Main MeMory Data Base
Main MeMory Data BaseMain MeMory Data Base
Main MeMory Data Base
 
Downscaling: The Achilles heel of Autoscaling Apache Spark Clusters
Downscaling: The Achilles heel of Autoscaling Apache Spark ClustersDownscaling: The Achilles heel of Autoscaling Apache Spark Clusters
Downscaling: The Achilles heel of Autoscaling Apache Spark Clusters
 
Internet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IVInternet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IV
 
Ch8
Ch8Ch8
Ch8
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen
 
Chapter07_ds.ppt
Chapter07_ds.pptChapter07_ds.ppt
Chapter07_ds.ppt
 
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters
Ceph Day Amsterdam 2015: Measuring and predicting performance of Ceph clusters
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
 
Scaling up Machine Learning Algorithms for Classification
Scaling up Machine Learning Algorithms for ClassificationScaling up Machine Learning Algorithms for Classification
Scaling up Machine Learning Algorithms for Classification
 
07-MemoryManagement.ppt
07-MemoryManagement.ppt07-MemoryManagement.ppt
07-MemoryManagement.ppt
 
UNIT IV.pptx
UNIT IV.pptxUNIT IV.pptx
UNIT IV.pptx
 
Project Presentation Final
Project Presentation FinalProject Presentation Final
Project Presentation Final
 
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
Modeling, estimating, and predicting Ceph (Linux Foundation - Vault 2015)
 
Training Webinar: Enterprise application performance with distributed caching
Training Webinar: Enterprise application performance with distributed cachingTraining Webinar: Enterprise application performance with distributed caching
Training Webinar: Enterprise application performance with distributed caching
 

More from Shahid Riaz

Shimla deputation (1906)
Shimla deputation (1906)Shimla deputation (1906)
Shimla deputation (1906)Shahid Riaz
 
#Syed ahmad shaheed barailvi
#Syed ahmad shaheed barailvi#Syed ahmad shaheed barailvi
#Syed ahmad shaheed barailviShahid Riaz
 
How to program in c++ with 100 examples
How to program in c++ with 100 examples  How to program in c++ with 100 examples
How to program in c++ with 100 examples Shahid Riaz
 
Virtual private networks in theory and practice
Virtual private networks in theory and practiceVirtual private networks in theory and practice
Virtual private networks in theory and practiceShahid Riaz
 
Database systems administration week 1
Database systems administration week 1Database systems administration week 1
Database systems administration week 1Shahid Riaz
 
Database systems administration traning 02
Database systems administration traning 02Database systems administration traning 02
Database systems administration traning 02Shahid Riaz
 
Database systems administration traning 02
Database systems administration traning 02Database systems administration traning 02
Database systems administration traning 02Shahid Riaz
 
Database systems administration traning 01
Database systems administration traning 01Database systems administration traning 01
Database systems administration traning 01Shahid Riaz
 
Database systems administration traning 0
Database systems administration traning 0Database systems administration traning 0
Database systems administration traning 0Shahid Riaz
 
Database systems administration traning 04
Database systems administration traning  04Database systems administration traning  04
Database systems administration traning 04Shahid Riaz
 
Managing people and organizing team
Managing people and organizing teamManaging people and organizing team
Managing people and organizing teamShahid Riaz
 
Lec 1 intro to internet
Lec 1 intro to internetLec 1 intro to internet
Lec 1 intro to internetShahid Riaz
 
Course guidlines course book it 3548
Course guidlines course book it 3548Course guidlines course book it 3548
Course guidlines course book it 3548Shahid Riaz
 
Lecture12 software design class diagram
Lecture12 software design class diagramLecture12 software design class diagram
Lecture12 software design class diagramShahid Riaz
 
Lecture11 use case sequence diagram
Lecture11 use case sequence diagramLecture11 use case sequence diagram
Lecture11 use case sequence diagramShahid Riaz
 
Lecture10 use case model operation contracts
Lecture10 use case model operation contractsLecture10 use case model operation contracts
Lecture10 use case model operation contractsShahid Riaz
 
Lecture9 domain model visualizing
Lecture9 domain model visualizingLecture9 domain model visualizing
Lecture9 domain model visualizingShahid Riaz
 
Lecture8 system sequence
Lecture8 system sequenceLecture8 system sequence
Lecture8 system sequenceShahid Riaz
 
Lecture7 use case modeling
Lecture7 use case modelingLecture7 use case modeling
Lecture7 use case modelingShahid Riaz
 
Lecture6 activity diagrams
Lecture6 activity diagramsLecture6 activity diagrams
Lecture6 activity diagramsShahid Riaz
 

More from Shahid Riaz (20)

Shimla deputation (1906)
Shimla deputation (1906)Shimla deputation (1906)
Shimla deputation (1906)
 
#Syed ahmad shaheed barailvi
#Syed ahmad shaheed barailvi#Syed ahmad shaheed barailvi
#Syed ahmad shaheed barailvi
 
How to program in c++ with 100 examples
How to program in c++ with 100 examples  How to program in c++ with 100 examples
How to program in c++ with 100 examples
 
Virtual private networks in theory and practice
Virtual private networks in theory and practiceVirtual private networks in theory and practice
Virtual private networks in theory and practice
 
Database systems administration week 1
Database systems administration week 1Database systems administration week 1
Database systems administration week 1
 
Database systems administration traning 02
Database systems administration traning 02Database systems administration traning 02
Database systems administration traning 02
 
Database systems administration traning 02
Database systems administration traning 02Database systems administration traning 02
Database systems administration traning 02
 
Database systems administration traning 01
Database systems administration traning 01Database systems administration traning 01
Database systems administration traning 01
 
Database systems administration traning 0
Database systems administration traning 0Database systems administration traning 0
Database systems administration traning 0
 
Database systems administration traning 04
Database systems administration traning  04Database systems administration traning  04
Database systems administration traning 04
 
Managing people and organizing team
Managing people and organizing teamManaging people and organizing team
Managing people and organizing team
 
Lec 1 intro to internet
Lec 1 intro to internetLec 1 intro to internet
Lec 1 intro to internet
 
Course guidlines course book it 3548
Course guidlines course book it 3548Course guidlines course book it 3548
Course guidlines course book it 3548
 
Lecture12 software design class diagram
Lecture12 software design class diagramLecture12 software design class diagram
Lecture12 software design class diagram
 
Lecture11 use case sequence diagram
Lecture11 use case sequence diagramLecture11 use case sequence diagram
Lecture11 use case sequence diagram
 
Lecture10 use case model operation contracts
Lecture10 use case model operation contractsLecture10 use case model operation contracts
Lecture10 use case model operation contracts
 
Lecture9 domain model visualizing
Lecture9 domain model visualizingLecture9 domain model visualizing
Lecture9 domain model visualizing
 
Lecture8 system sequence
Lecture8 system sequenceLecture8 system sequence
Lecture8 system sequence
 
Lecture7 use case modeling
Lecture7 use case modelingLecture7 use case modeling
Lecture7 use case modeling
 
Lecture6 activity diagrams
Lecture6 activity diagramsLecture6 activity diagrams
Lecture6 activity diagrams
 

Recently uploaded

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

4 memory management bb

  • 2. To cover •Overview. •Strategies for Allocating Variables to Memory. •Design Patterns for Limited Memory. •Memory Management in Mobile Java. •Symbian OS Memory Management.
  • 3. Overview •Memory management is different from managing some other resources •Tangling everywhere •Mobile devices memory is a critical resource - cost of the device low - running programs are competing for it •Explicitly allocate memory in many imperative languages, such as C and C++ •Memory consumption in mobile devices a cross- cutting problem
  • 4. Strategies for Allocating Variables to Memory •Stack and the heap are principle memory areas •Run-time infrastructure and the programmer are responsible for their management •In heap, sharing of data is easy and natural •Stack-based variables references should use with care - stack increases and decreases, and may overwrite referred data •Statically allocated to a permanent location or dynamically allocated from stack or heap
  • 5. Static Allocation •Throughout program life variable remains allocated •Memory locations used by it cannot be deallocated. int * pointer_to_static() { static int x; return &x; } •Singleton pattern - a single instance (or a few instances) of a class, and make it known to all subsystems.
  • 6. Stack •Transient objects - Those that live only a limited period of time, are to be stored in the stack. int * pointer_to_int() { int x; return &x; } •Returned reference points to a location in the memory •Potentially overwritten by any later functions that will be called by the program
  • 7.
  • 8.
  • 9. Stack Limitations •Hard-to-repeat errors and complex debugging tasks. •Stack could exhaust when data is accidentally copied by making a method or function call •Better to allocate big objects from the heap •to ensure that the object is not accidentally modified via a reference, const definition can be used where applicable
  • 10. Heap •All data structures whose size or structure can be altered dynamically must be allocated to the heap. •Since, unknown structures are impossible to reserve enough space from the stack. •Global object, should be allocated memory from heap. •garbage collection is a responsibility of the caller if there is no automation •Heap can be slower than using the stack
  • 11. Design Patterns for Limited Memory •Design should be based on the most adequate data structure, which offers the right operations. - Use singly link list instead double if it is enough. •Better performance if support can be gained from cache. •Design patterns created for help in designing small memory software. •Linear Data Structures: - Where different elements are located next to each other in the memory. - For instance, implementations of lists and tree-like data structures. - Linear data structures are generally better for memory management than non-linear ones.
  • 12. Design Patterns for Limited Memory •Less fragmentation: - Linear data structures occupy memory place from one location. - whereas non-linear ones can be located in different places. - Obviously, the former results in less possibility for fragmentation. •Less searching overhead: - Reserving a linear block of memory for several items only takes one search for a suitable memory element in the run- time environment - whereas non-linear structures require one request for memory per allocated element. - Combined with a design where one object allocates a number of child objects, this may also lead to a serious performance problem.
  • 13. Design Patterns for Limited Memory •Design-time management: - Linear blocks are easier to manage at design time, as fewer reservations are made. - This usually leads to cleaner designs. •Monitoring: - Addressing can be performed in a monitored fashion, because it is possible to check that the used index refers to a legal object. • Cache improvement: - using linear data structures, it is more likely that the next data element is already in cache
  • 14. Design Patterns for Limited Memory • Index uses less memory: - An absolute reference to an object usually consumes 32 bits, - whereas by allocating objects to a vector of 256 objects, assuming that this is the upper limit of objects, an index of only 8 bits can be used. - Furthermore, it is possible to check that there will be no invalid indexing.
  • 15. Design Patterns for Limited Memory •Basic Design Decisions: •Allocate all memory at the beginning of a program. - Reserving all the resources is particularly attractive when the most important or mandatory features like emergency calls •Allocate memory for several items, even if you only need one. - a number of objects is reserved with one allocation request. - less complex structure in the memory. - fewer memory allocations, and cache use is improved. •Use standard allocation sizes. - easy to reuse a deallocated area in the memory. - fragmentation of memory can be prevented.
  • 16. Design Patterns for Limited Memory •Reuse objects. - programmer actively participates in the process of selecting object construction and destruction policy • Release early, allocate late. - objects occupying a large amount of memory are deallocated before allocating new objects. •Use permanent storage or ROM when applicable. - in case of battery removal from the device, unsaved data will be lost - save all data to permanent storage as soon as possible. •Avoid recursion. - size of a single stack frame in KVM is 28 bytes (7×4 bytes). - functions calling themselves recursively can end up using a lot of stack
  • 17. Design Patterns for Limited Memory •Data Packing - way to reduce memory consumption. •Consider word alignment. struct S { char c1; // Actually a boolean. int i; char c2; }; - three words are required - By changing the data structure to struct S { char c1; // Actually a boolean. char c2; int i; };
  • 18. Design Patterns for Limited Memory - c1 and c2 fit in the same word. - improvement can be gained by using only one bit for the Boolean value, assuming that there would be some other data to include in the saved bits.
  • 19. Design Patterns for Limited Memory •Use compression with care. - May impair performance while compressing data or opening files - three different compression techniques: - Table compression • also referred to as nibble coding or Huffman coding • encoding each element of data in a variable number of bits • so that the more common elements require fewer bits. - Difference coding • representing sequences of data according to the differences between them. - Adaptive compression • is based on algorithms that analyze the data to be compressed
  • 20. Design Patterns for Limited Memory •Use efficient resource storage format. - ensure that images, sounds, and movies are stored in the most efficient way - possible to save some space by combining many image files into one image file.
  • 21. Design Patterns for Limited Memory •Discussion - memory management are not problem-free. - when improving a certain property of software design, some other part is downgraded or compromised. •Increased minimal memory usage. - simplistic implementation. •Decreased flexibility. - it is possible that some hardware configurations are invalidated. •Downgraded performance. - Using some form of compression can lead to decreased memory use - packing a lot of information into the same memory word can lead to downgraded performance.
  • 22. Design Patterns for Limited Memory •Longer initialization and shutdown sequences - it is possible to handle some of the operations associated with memory at the beginning or at the end of the program - rather than in the middle of the execution, startup and termination of the program can become slower. • Potential unintuitiveness in designs - When an experienced designer composes a design in a memory-aware fashion, - some of the decisions can be unintuitive to less experienced developers. •Impaired reusability - The more one addresses particularities of a certain design problem in the solution, - the less likely it is that the same solution could be used again in another context.
  • 23. Design Patterns for Limited Memory •To summarize, it is a necessity to balance between the different requirements addressing the properties of designs.
  • 24. Memory Management in Mobile Java •Code optimization could be error prone - Such systems running on Virtual Machines - May cause abstraction leakage • Motivation - Despite of managing resources automatically, use appropriate data structures (garbage collection using DS) - For instance, implementing a stack of references on a virtual machine - The stack is implemented as a vector. - An index (size) to the vector is used as the stack pointer - Stack pointer is incremented by one, when a new item is added. Public void push(Object e) { ensureCapacity( ); // Check that slots are available. elements [size++] = e; }
  • 25.
  • 26. - Similarly, when an element is removed from the stack, the stack pointer is decremented by one. public Object pop(){ if(size == 0) throw new EmptyStackException(); return elements[--size]; } - Reference to garbage collection, there can be ‘ghost’ references to objects that are unusable - but remain valid and accessible in the vector used in the implementation. - Such ‘ghosts’ are a result of executing several push and pop operations. - The garbage collector is not allowed to deallocate them before the last reference to them has been erased, and having an accidental unused reference counts in this respect.
  • 27. - the problem can be solved by setting vector element to zero in method pop: public Object pop() { if(size == 0) throw new EmptyStackException(); Object result = elements[--size]; elements[size] = null; return result; }
  • 28. Rules of Thumb for Mobile Java •Avoid small classes. - it is better for memory consumption to merge small classes into bigger ones. - Usually inner classes contain only little functionality, like a particular listener of some user action. - keeping the number of different exceptions as small as possible. - For instance, the memory consumption of an application that was implemented using two different structural alternatives, shrank to almost half from 14 019 bytes to 7467 bytes when the number of classes was reduced from 14 to 1 without altering the behavior of the application (Hartikainen et al. 2006). •Avoid dependencies. - one might save memory by removing references
  • 29. •Select the size when relevant, and manage vector/string usage. - whenever possible, by providing the size of the vector instead of using the default size •Consider using array versus using vector. - the difference between array- and vector-based implementations is relevant both in terms of the number of objects and used bytes. - vector effectively need to wrap integers to objects to be able to store their values - an implementation where the correct size is given in the constructor, allocates up to 24% less memory in terms of size.
  • 30. •Use StringBuffer. - Concatenating String with the + operator or with the append method consumes memory as the virtual machine needs to create temporary objects. - Using strings // String based implementation. public void useString() { String s = ""; for(int i = 0; i < AMOUNT; i++) { s = s + "a"; } } Using StringBuffer // StringBuffer based implementation. public void useStringBuffer() { String s = ""; StringBuffer sb = new StringBuffer(AMOUNT); for(int i = 0; i < AMOUNT; i++) { sb = sb.append("a"); } s = sb.toString(); }
  • 31. •Manage class and object structure. - Inheritance can sometimes cost memory - When creating an object of a child class also its parent class needs to be loaded - All the variables from the parent are present in a child object - hierarchy of classes constructed can lead to superfluous loading and memory consumption. •Generate less garbage. - Reusing old objects to avoid making garbage. •Consider obfuscation. - majority of the content of a Java library often consists of metainformation and strings. - one can reduce footprint by obfuscating the names of public instance variables and methods, classes, and packages to a smaller form.
  • 32. •Handle array initialization. - Long arrays static initializer can consume a lot of space - Improved tool support can offer solutions that consume less memory. - In practice, the difference only becomes meaningful when the size of an array is over 1000 (Hartikainen, 2005).