Download Memory Management on Smartphones

Transcript
CHAPTER 4. DESIGN AND IMPLEMENTATION
36
(see section 6.1). The output of bytes allocated and bytes requested give
a measure of how much space is wasted due to over-allocation of cells, and
outputting the heap size will give a measure of memory fragmentation, when
compared to the live data used; this then can be used to assess the allocator.
The total live data can be calculated from the traces when processing the
data, and hence does not need to be recorded.
To characterise the smartphone applications, a record of the number of
allocations of an object of each particular size can be used (thus obtaining
a frequency distribution of object sizes). The number of objects can be
calculated when processing the data, hence no record of this needs to be
kept as part of the tracer, only the size of the object.
Method
Due to the extensible nature of the Symbian OS, the tracing was implemented
as a class called MyHeap that extended the existing Symbian allocator. The
new class was compiled as a polymorphic DLL file (see section 3.1), so the
Symbian OS would pick it up and automatically use it instead of using the
built-in allocator (RHeap).
Each particular procedure (Alloc, ReAlloc and Free) needs to be overridden with an equivalent procedure that includes tracing.Constructors need to
be specified, so initialisation is done correctly (calling through to the parent
class). Additionally, all the methods that are used to create a ChunkHeap
(see section 3.3) need to be re-implemented to use MyHeap instead of the
Symbian RHeap.
To avoid having issues with the recording of the traces interfering with the
allocation/deallocation of memory (by causing extra allocations), the records
were stored as a large array of structs, where each struct contained enough
information to be able to obtain an allocation profile (see section 4.1.3). This
way, a non-heap area of memory is set aside for the traces.
Once the traces have been collected, it is necessary to have them written
out to a file. For this, an extra function was used to go through the parts of
the array that had been used to store traces, and write the structs out to a
file (see section 4.2.3). Given that the Symbian OS has its own file system,
it would be easiest to write the traces to a files in this filing system, which is
also then accessible by the host system if running the emulator (see section
4.1.2). Additionally, unique names should be given to the trace files so they
can be easily identified, and so that multiple programs (and hence traces)
can be obtained in each session.
Due to the possibility of switching memory allocators in the Symbian OS
(see section 3.4), each application should, in its startup code, switch to using