<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Calibri" size="2"><span style="font-size:11pt;">
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&gt; -----Original Message-----</div>
<div>&gt; Take a look at the benchmark suite at</div>
<div>&gt; <a href="http://hg.python.org/benchmarks/">http://hg.python.org/benchmarks/</a></div>
<div>&gt; The test runner has an -m option that profiles memory usage, you could take</div>
<div>&gt; a look at how that is implemented</div>
<div>&gt; </div>
<div>&nbsp;</div>
<div>Yes, out of process monitoring of memory as reported by the OS.&nbsp; We do gather those counters as well on clients and servers.</div>
<div>But they don't give you the granularity you want when checking for memory leaks and memory usage by certain algorithms.</div>
<div>In the same way that the unittests have reference leak reports, they could just have memory usage reports, if the underlying allocator supported that.</div>
<div>&nbsp;</div>
<div>FYI the current state of affairs of the cPython 2.7 branch we use is as follows:</div>
<div>1) We allow the API user to specify the base allocator python uses, both for regular allocs and allocating blocks for the obmalloc one, using:</div>
<div>&nbsp;</div>
<div>/* Support for custom allocators */</div>
<div>typedef void *(*PyCCP_Malloc_t)(size_t size, void *arg, const char *file, int line, const char *msg);</div>
<div>typedef void *(*PyCCP_Realloc_t)(void *ptr, size_t size, void *arg, const char *file, int line, const char *msg);</div>
<div>typedef void (*PyCCP_Free_t)(void *ptr, void *arg, const char *file, int line, const char *msg);</div>
<div>typedef size_t (*PyCCP_Msize_t)(void *ptr, void *arg);</div>
<div>typedef struct PyCCP_CustomAllocator_t</div>
<div>{</div>
<div>&nbsp;&nbsp;&nbsp; PyCCP_Malloc_t&nbsp; pMalloc;</div>
<div>&nbsp;&nbsp;&nbsp; PyCCP_Realloc_t pRealloc;</div>
<div>&nbsp;&nbsp;&nbsp; PyCCP_Free_t&nbsp;&nbsp;&nbsp; pFree;</div>
<div>&nbsp;&nbsp;&nbsp; PyCCP_Msize_t&nbsp;&nbsp; pMsize;&nbsp;&nbsp;&nbsp; /* can be NULL, or return -1 if no size info is avail. */</div>
<div>&nbsp;&nbsp;&nbsp; void&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *arg;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* opaque argument for the functions */</div>
<div>} PyCCP_CustomAllocator_t;</div>
<div>&nbsp;</div>
<div>/* To set an allocator!&nbsp; use 0 for the regular allocator, 1 for the block allocator.</div>
<div> * pass a null pointer to reset to internal default</div>
<div> */</div>
<div>PyAPI_FUNC(void) PyCCP_SetAllocator(int which, const PyCCP_CustomAllocator_t *); /* for BLUE to set the current context */</div>
<div>&nbsp;</div>
<div>/* internal data member */</div>
<div>extern PyCCP_CustomAllocator_t _PyCCP_CustomAllocator[];</div>
<div>&nbsp;</div>
<div>2) using ifdefs, the macros will delegate all final allocations through these allocators.&nbsp; This includes all the &quot;naked&quot; malloc calls scattered about, they are patched up using #defines.</div>
<div>&nbsp;</div>
<div>3) Additionally, there is an internal layer of management, before delegating to the external allocators.&nbsp; This internal manager provides statistics, exposed through the &quot;sys&quot; module.</div>
<div>&nbsp;</div>
<div>The layering is something like this, all more or less definable by pre-processor macros. (raw malloc() is turned into something else via pre-processor magic and a special &#8220;patch_malloc.h&#8221; file added to the modules which uses raw malloc())</div>
<div>&nbsp;</div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PyMem_Malloc()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PyObject_Malloc()</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; v&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mem bookkeeping&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj bookkeeping</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v</font></div>
<div><font face="Courier New"> malloc()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; obmallocator</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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sp;&nbsp;&nbsp; |</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v</font></div>
<div><font face="Courier New">&nbsp;&nbsp;&nbsp; malloc() or vectored allocator specified through API function</font></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Cheers,</div>
<div>&nbsp;</div>
<div>K</div>
<div>&nbsp;</div>
</span></font>
</body>
</html>

AltStyle によって変換されたページ (->オリジナル) /