python for console game development, memory tracking
Simon Burton
simonb at NOTTHISBIT.webone.com.au
Sun Apr 25 06:51:22 EDT 2004
On Sat, 24 Apr 2004 07:13:06 +0000, Moosebumps wrote:
...
>
> Before I even begin investigating though, there is a major question I
> have: How can you track the memory usage of Python? I would like to be
> able to track allocations by function / class, etc. I have googled and
> seen a bunch of threads with 1 guy asking the same exact question that I
> am, and no responses, which leads me to believe it's very easy or not
> possible. This would be dealbreaker unfortunately. But I am optimistic
> that Python is well designed so there must be some solution.
>
> thanks,
> MB
I was just investigating this myself. Check out pymem.h in the source:
/* SCENARIOS
Here are two scenarios by Vladimir Marangozov (the author of the
memory allocation redesign).
1) Scenario A
Suppose you want to use a debugging malloc library that collects info on
where the malloc calls originate from. Assume the interface is:
d_malloc(size_t n, char* src_file, unsigned long src_line) c.s.
In this case, you would define (for example in pyconfig.h) :
#define PyCore_MALLOC_FUNC d_malloc
...
#define PyCore_MALLOC_PROTO (size_t, char *, unsigned long)
...
#define NEED_TO_DECLARE_MALLOC_AND_FRIEND
#define PyCore_MALLOC(n) PyCore_MALLOC_FUNC((n), __FILE__, __LINE__)
...
2) Scenario B
Suppose you want to use malloc hooks (defined & initialized in a 3rd party
malloc library) instead of malloc functions. In this case, you would
define:
#define PyCore_MALLOC_FUNC (*malloc_hook)
...
#define NEED_TO_DECLARE_MALLOC_AND_FRIEND
and ignore the previous definitions about PyCore_MALLOC_FUNC, etc.
*/
Simon.
More information about the Python-list
mailing list