|
resonance 1.0.1
|
#include <stddef.h>#include <stdio.h>

Go to the source code of this file.
Functions | |
| void * | AllocateTaggedMemory (size_t nSize, const char *pszClass) |
| Allocate a block for one object of a named class. | |
| void | OperatorDeleteOverride (void *pBlock, const char *pszClass) |
| Release a block that AllocateTaggedMemory() handed out. | |
| char * | MemGetCurrentTag () |
| Address the buffer the STL allocator hook bills its allocations to. | |
| void | MemSetStlTag (const char *pszKind, int nElemSize) |
| Bill the next STL allocation to a container kind and element size. | |
| void * | MemAllocTagged (size_t nSize, const char *pszTag, int nLine) |
| Allocate a block and record the request against a tag. | |
| void | MemFreeTagged (void *pBlock, const char *pszTag, int nLine) |
| Release a block and record the release against a tag. | |
| int | MemLogFindSource (const char *pszName) |
| Find or claim the report row for a source name. | |
| void * | MemReallocTagged (void *pBlock, size_t nSize, const char *pszTag, int nLine) |
| Resize a block and record the move against a tag. | |
| void | MemLogWriteMarker (const char *pszText) |
| Write a marker line into the memory report. | |
| void | MemCloseLogAndReport () |
| Close the memory report and print a summary of the heap. | |
| void | MemOpenLog (const char *pszPath) |
| Open the memory report and paint the stack. | |
| void | MemLogCloseAndContinue () |
| Start a new report file that retains everything written so far. | |
| void | MemLogPrint (const char *pszText) |
| Write text to the memory report while logging is on. | |
| void | MemLogBeginCount () |
| Clear the per-tag accounting table and start charging it. | |
| int | MemLogEndCount (char *pszReport, int nReportSize) |
| Stop charging the accounting table and format its totals. | |
| void | MemLogSourceInit () |
| Allocate the per-block tracking table and clear the per-source table. | |
| void | MemLogSourceTrackRealloc (const char *pszSource, void *pNew, void *pOld, int nSize) |
| Move a tracked block to its new address after a resize. | |
| void | MemLogSourceReport (const char *pszTitle, FILE *pFile) |
| Print the per-source table, sorted by name. | |
| void | DumpHeapMemoryLog (int nIndex) |
| Write the memory statistics files and probe the largest possible allocation. | |
| void * | HeapAlloc (size_t nSize) |
| Take a block from the backing allocator. | |
| void | HeapFree (void *pBlock) |
| Give a block back to the backing allocator. | |
| void * | HeapRealloc (void *pBlock, size_t nSize) |
| Resize a block through the backing allocator. | |
| void | ReportHeapCapacity () |
| Log how much of the backing allocator is free, then give it all back. | |
| void * AllocateTaggedMemory | ( | size_t | nSize, |
| const char * | pszClass ) |
Allocate a block for one object of a named class.
This is the allocator every class-specific operator new in the image forwards to. Each of those is eight instructions that pass the request through and supply the class name as the second argument. 637 call sites exist and at least 41 distinct class names appear among them, including the qualified forms Rnd::Mesh and Rnd::Cam. The tag reaches the accounting table unreduced, and the failure message reads NEW ALLOCATION FAILURE, class: s, size: d. The request is raised to one byte when it is zero, and a failure is fatal.
| nSize | The block size in bytes. |
| pszClass | The class name to bill the allocation to. |
| void OperatorDeleteOverride | ( | void * | pBlock, |
| const char * | pszClass ) |
Release a block that AllocateTaggedMemory() handed out.
The class name reaches the log line unreduced. Unlike MemFreeTagged() this path does not test the block against the zones.
| pBlock | The block to release. |
| pszClass | The class name the allocation was billed to. |
| char * MemGetCurrentTag | ( | ) |
Address the buffer the STL allocator hook bills its allocations to.
The buffer is the one MemSetStlTag() formats into, and MemAllocTagged() rewinds it to stl_unk after every tagged allocation. Callers pass the result straight on as a tag.
| void MemSetStlTag | ( | const char * | pszKind, |
| int | nElemSize ) |
Bill the next STL allocation to a container kind and element size.
The two arguments are formatted as s.d. That produces a tag such as stl_vector.8. Every STL allocation hook calls this and then passes MemGetCurrentTag() to MemAllocTagged().
| pszKind | The container kind, for example stl_vector. |
| nElemSize | The element size in bytes. |
| void * MemAllocTagged | ( | size_t | nSize, |
| const char * | pszTag, | ||
| int | nLine ) |
Allocate a block and record the request against a tag.
The tag is normally the caller's __FILE__ or the class name. Totals per tag accumulate into the accounting table, and the log line uses only the tag's basename. A failure is fatal.
| nSize | The block size in bytes. |
| pszTag | The tag to bill the allocation to. |
| nLine | The caller's line number. |
| void MemFreeTagged | ( | void * | pBlock, |
| const char * | pszTag, | ||
| int | nLine ) |
Release a block and record the release against a tag.
Releasing a block that belongs to a zone is fatal, because a zone hands out bump-pointer slices that cannot be reclaimed individually.
| pBlock | The block to release. |
| pszTag | The tag the allocation was billed to. |
| nLine | The caller's line number. |
| int MemLogFindSource | ( | const char * | pszName | ) |
Find or claim the report row for a source name.
The name is reduced to its basename, then matched against the interned source table of 128 rows. A name of 40 characters or more, and an exhausted table, are both fatal. The table is separate from the per-tag accounting table.
| pszName | The source name, normally a __FILE__. |
| void * MemReallocTagged | ( | void * | pBlock, |
| size_t | nSize, | ||
| const char * | pszTag, | ||
| int | nLine ) |
Resize a block and record the move against a tag.
Resizing a block that belongs to a zone is fatal, for the same reason releasing one is. On failure the report uses the tag and line unchanged.
| pBlock | The block to resize. |
| nSize | The new size in bytes. |
| pszTag | The tag the allocation was billed to. |
| nLine | The caller's line number. |
| void MemLogWriteMarker | ( | const char * | pszText | ) |
Write a marker line into the memory report.
Performs no work while logging is off. The frame loop and HHeapLogBasicStats() are the callers.
| pszText | The text to mark. |
| void MemCloseLogAndReport | ( | ) |
Close the memory report and print a summary of the heap.
Closing is skipped when the report was never opened, and otherwise also clears the logging flag. The summary is the ten fields of the C library's mallinfo() and, once MemOpenLog() has painted the stack, the stack depth reached. DumpHeapMemoryLog(0) runs last. Fatal() calls this, and MemOpenLog() registers it with atexit().
| void MemOpenLog | ( | const char * | pszPath | ) |
Open the memory report and paint the stack.
A path opens the report for writing and turns logging on when the file opens. Either way the three linker symbols _stack, _stack_size, and _end are logged, every byte of the stack below its top 0x2000 bytes is set to u so that a later report can measure the depth reached, and MemCloseLogAndReport() is registered with atexit().
The name is inferred.
| pszPath | The report path, or null to paint the stack only. |
| void MemLogCloseAndContinue | ( | ) |
Start a new report file that retains everything written so far.
The open report is closed, its content is copied into a file named after the original path with _N before the extension, and writing continues there. The mallinfo summary and the stack depth are logged afterwards whether or not a report was open. The title is the one its log line gives.
| void MemLogPrint | ( | const char * | pszText | ) |
Write text to the memory report while logging is on.
The image has no caller. The name is inferred.
| pszText | The text. |
| void MemLogBeginCount | ( | ) |
Clear the per-tag accounting table and start charging it.
Record 0 is labelled Other_Sources. Rnd::AsyncLoader's poll brackets a load with this and MemLogEndCount().
| int MemLogEndCount | ( | char * | pszReport, |
| int | nReportSize ) |
Stop charging the accounting table and format its totals.
The report begins Memory Allocated: d and adds one line per labelled record. Record 0 appears only when it has been charged. A line that would leave less than 0x40 bytes of the buffer is replaced by ...REPORT TOO LONG FOR BUFFER! and ends the report.
| pszReport | Receives the report. |
| nReportSize | The size of the buffer. |
| void MemLogSourceInit | ( | ) |
Allocate the per-block tracking table and clear the per-source table.
The block table is 32 MB, 0x200000 slots of 16 bytes. The image has no caller, so block tracking never runs in the shipped build. The name is inferred.
| void MemLogSourceTrackRealloc | ( | const char * | pszSource, |
| void * | pNew, | ||
| void * | pOld, | ||
| int | nSize ) |
Move a tracked block to its new address after a resize.
An untracked old block is reported and recorded as a new allocation. Otherwise the entry takes the new address and size and its source's byte totals move by the difference. The title is the one its log line gives.
| pszSource | The source the block is billed to. |
| pNew | The block after the resize. |
| pOld | The block before the resize. |
| nSize | The new size in bytes. |
| void MemLogSourceReport | ( | const char * | pszTitle, |
| FILE * | pFile ) |
Print the per-source table, sorted by name.
Performs no work before MemLogSourceInit(). DumpHeapMemoryLog() is the one caller. The name is inferred.
| pszTitle | The heading line. |
| pFile | The stream to write, or null for standard output. |
| void DumpHeapMemoryLog | ( | int | nIndex | ) |
Write the memory statistics files and probe the largest possible allocation.
It writes memdump_d.txt through MemLogSourceReport(). It then writes memstat_d.txt with the largest single allocation, probed downward from 128 megabytes in tenths, and the number of 2048-byte and 128-byte blocks that fit, each counted to at most 65536 and released again. Each line also goes to the log. Neither file open is checked.
| nIndex | The number the file names carry. |
| void * HeapAlloc | ( | size_t | nSize | ) |
Take a block from the backing allocator.
The routine behaves as newlib's malloc, toolchain C library linked as shipped. It loads the reentrancy structure at 0x007819cc and calls _malloc_r at 0x0059b528. It is not the Heap class in os/heap.h, the arena the embedded Python allocates from.
| nSize | The block size in bytes. |
| void HeapFree | ( | void * | pBlock | ) |
Give a block back to the backing allocator.
The routine behaves as newlib's free, toolchain C library linked as shipped. It loads the same reentrancy structure and tail-calls _free_r at 0x005da3b0.
| pBlock | The block to release. |
| void * HeapRealloc | ( | void * | pBlock, |
| size_t | nSize ) |
Resize a block through the backing allocator.
The toolchain routine underneath is at 0x00589278. Unlike the other two wrappers this one has no out-of-line copy, because MemReallocTagged() is its only caller and inlines it.
| pBlock | The block to resize. |
| nSize | The new size in bytes. |
| void ReportHeapCapacity | ( | ) |
Log how much of the backing allocator is free, then give it all back.
Blocks of 2048 bytes are taken through HeapAlloc() until a request fails, the count and the total are logged, and every block is released through HeapFree(). The name is inferred. The binary places the routine at the head of the TexturePairRecord unit, and it has no caller.