I'm currently replacing the Quake 3 game code (not the rendering,
sound, or collision detection pieces) with Python. I've now
successfully loaded Python modules and made callbacks to them, rendered
maps, written some fly-through code, and embedded a Python interactive
mode into the console (which is way, way cool).
It's my first C API project, and I want to make sure I've got my
reference counting right. I *could* go through the API docs and
determine which function returns what kind of PyObject pointer (shared,
new, etc.), and double- and triple-check all my code. In fact, I am,
but it's definitely prone to error, because I'm not as perfect as I'd
like to think. I want a more automatic way of doing it, or at least a
good way of checking correctness.
When the game is just running and spinning out frames, I *know* that no
new memory should be allocated that isn't immediately deallocated
(memory usage should be constant), and that Python's total reference
count shouldn't change. I can also set up tests that exercise various
parts of the Q3 engine / Python game thunking layer and support objects
that should leave memory in the same state it was at when they started.
Is there a way I can get hold of these kinds of statistics for
debugging?
Neil 3 1817
lord trousers wrote: Is there a way I can get hold of these kinds of statistics for debugging?
This is best done when Python is build in debug mode.
sys.gettotalref count then gives you the number of INCREF
calls for which no DECREF has been made; you said that
this shouldn't change.
If it does change, sys.get_counts( ) will give you the
number of objects per type.
Furthermore, sys.getobjects( ) will give you a list of
all objects allocated (excluding the result list).
HTH,
Martin
Martin v. Löwis wrote: lord trousers wrote: Is there a way I can get hold of these kinds of statistics for debugging?
This is best done when Python is build in debug mode. sys.gettotalref count then gives you the number of INCREF calls for which no DECREF has been made; you said that this shouldn't change.
If it does change, sys.get_counts( ) will give you the number of objects per type.
Furthermore, sys.getobjects( ) will give you a list of all objects allocated (excluding the result list).
HTH, Martin
Wonderful! That's just what I was looking for.
Is this kind of thing documented somewhere public? (As attributes that
only show up in the debug build, they aren't documented in the regular
library docs.) There might be more nifty goodies like this, and I'd
like to check them out.
Thanks again!
Neil
[lord trousers] Is there a way I can get hold of these kinds of statistics for debugging?
[Martin v. Löwis] This is best done when Python is build in debug mode. sys.gettotalref count then gives you the number of INCREF calls for which no DECREF has been made; you said that this shouldn't change.
If it does change, sys.get_counts( ) will give you the number of objects per type.
Furthermore, sys.getobjects( ) will give you a list of all objects allocated (excluding the result list).
[lord trousers] Wonderful! That's just what I was looking for.
Is this kind of thing documented somewhere public? (As attributes that only show up in the debug build, they aren't documented in the regular library docs.) There might be more nifty goodies like this, and I'd like to check them out.
Actually, sys.getcounts() only exists in a COUNT_ALLOCS build (which
can be combined with a debug build, but is not implied by a debug
build).
All that (and other esoterica) is documented in
Misc/SpecialBuilds.t xt, in any Python source distribution. The Python
Windows installer does not contain that file. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Elbert Lev |
last post by:
Please correct me if I'm wrong.
Python (as I understand) uses reference counting to determine when to
delete the object. As soon as the object goes out of the scope it is
deleted. Python does not use garbage collection (as Java does).
So if the script runs a loop:
for i in range(100):
f = Obj(i)
|
by: Tony Johansson |
last post by:
Hello Experts!
I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that I don't understand
completely.
It says
"A garbarage collector, such as the one used in Java, maintains a record of
whether or not
an object is currentlys being used. An unused object is tagged as garbage,
|
by: Divick |
last post by:
Hi,
I am designing an API and the problem that I have is more of a
design issue. In my API say I have a class A and B, as shown below
class A{
public:
void doSomethingWithB( B * b)
{
//do something with b
//possibly store in a list
|
by: Fabian Steiner |
last post by:
I recently started learning C since I want to be able to write Python
extension modules. In fact, there is no need for it, but I simply want
to try something new ...
I tried to implement the bubblesort algorithm in C and to use it in
python; bubblesort.c compiles fine, but whenever I want to import the
modul and call the function I get a segmentation fault. This is what the
code looks like:
static PyObject *py_bubblesort(PyObject...
|
by: Huayang Xia |
last post by:
I get a python object by running a class' constructor. Then I need to
modify the instance's attribute just like obj.attr1.attr2 = 'a' if in
python's term.
PyObject* py_obj_attr1 = PyObject_GetAttrString(obj, "attr1");
PyObject_SetAttrString(py_obj_attr1, "attr2",
PyString_FromString("a"));
Py_DECREF(py_obj_attr1);
The object py_obj_attr1 is said to be a "New reference". It's
| |
by: Chris Thomasson |
last post by:
Here are the pre-alpha code downloads:
http://appcore.home.comcast.net/vzoom/refcount/
(both C and C++ api here...)
Here is some pre-alpha documentation:
http://appcore.home.comcast.net/vzoom/refcount/doc/
|
by: oec.deepak |
last post by:
Hi
Cn any one telll me what is Reference counting in C++.
|
by: Alf P. Steinbach |
last post by:
I once suggested in that SomeOne Else(TM) should propose
a string value class that accepted literals and char pointers and so on,
with possible custom deleter, and in case of literal strings just
carrying the original pointer.
In other words, for the simplest usage code:
* no overhead (just carrying a pointer or two), and
* no possibility of exceptions (for that case).
|
by: mathieu |
last post by:
Hi there
I have implemented a very simple smartpointer class (invasive
design). And I was wondering what should be the natural API when using
those in a Container.
I choose to define the following operator in my smartpointer class:
....
operator ObjectType * () const
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |