fastmm in depth
DESCRIPTION
FastMM in Depth. Primo ž Gabrijelčič, primoz @gabrijelcic.org www.thedelphigeek.com. Memory Management. “Do I really have to know anything about memory management?” No! Unless you live in the real world . Memory Management. strings. handles. forms. windows. objects. brushes. http. - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/2.jpg)
Memory Management
![Page 3: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/3.jpg)
Memory Management
“Do I really have to know anythingabout memory management?”
No!Unless you live in the real world
forms
objectsbrushes
windows
![Page 4: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/4.jpg)
‘The answer is’‘The answer is’
Behind the Scene
A simple program …a := 'The answer is';a := a + ' ' + IntToStr(42);
… causes not so simple flow of events.
‘42’‘The answer is 42’
![Page 5: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/5.jpg)
Allocate, Release
• Allocate– TClass.Create, GetMem, AllocateMem, New,
Create[Window,Handle,File…]
• Release– object.Destroy/Free, FreeMem, Dispose,
CloseHandle– Or in Delphi terms: Create, GetMem,
AllocateMem …; Destroy, Free, FreeMem
• .NET is different
![Page 6: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/6.jpg)
Memory Manager
• In the operating system• In the runtime library– Intermediary between the application and OS
• Speed• Decreased fragmentation
![Page 7: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/7.jpg)
‘What’s up Doc?’‘My memory block!’
Bugs, Bugs, Everywhere
• Reading outside allocated area
• Writing outside allocated area
• Using released memory
‘The answer is 42’
header
‘The answer is 42’
header
header
data
header
‘The answer is 42’‘My memory block!’‘What’s up Doc?’
![Page 8: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/8.jpg)
FastMM 4
![Page 9: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/9.jpg)
FastMM4
• The Fastcode ProjectMemory Manager Challenge
• Pierre le Riche, fastmm.sourceforge.net
• Included in Delphi 2006• Supports Delphi 4⇨, C++ Builder 4⇨,
Kylix 3
![Page 10: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/10.jpg)
Delphi MM vs. FastMM4
Delphi MM FastMM4
Speed Fragmentation Debugging Simplicity
• Uses FastMM4;
![Page 11: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/11.jpg)
FastMM4 Internals
• Three memory managers in one– Small blocks (< 2,5 KB)• Most frequently used (99%)• Medium blocks, subdivided into small blocks
– Medium blocks (2,5 – 260 KB)• Allocated in chunks (1,25 MB) and
subdivided into lists– Large blocks (> 260 KB)• Allocated directly by the OS
– Separate locks
![Page 12: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/12.jpg)
Other Memory Managers
• TopMM– www.topsoftwaresite.nl– Multithreaded programming
• SafeMM– cc.embarcadero.com/item/27241– Debugging
![Page 13: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/13.jpg)
Show me the code!
![Page 14: FastMM in Depth](https://reader036.vdocument.in/reader036/viewer/2022081508/5681434a550346895dafc628/html5/thumbnails/14.jpg)
Q & A