473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Heap cleanup in python extension

Hello Together,

Shortly what I'm doing:
- Extending python with boost.pthon extension
- Using python C-Api for datatypes in the extension
- extension has a thread (that can be stopped/started)
- thread started: extension updates a dict (given as parameter to the extension)
every 20 ms
- the dict looks like:
{int:{int:[float,float,float] int:[float,float,float], ...}}

Now my question:
I create the dict every 20 ms on the heap in the following way:
------------------------------
static PyObject* createPTDict()
{
static int aNumIter = 0;

PyObject* nRetDictPy = PyDict_New(); // dicto to return
PyObject* nToolIdPy = PyInt_FromLong(1234567);
PyObject* nLedDict = PyDict_New(); // dict containing 5 key,values

for (int aLedNum=0; aLedNum < 5; aLedNum++)
{
PyObject* aLedNumPy = PyInt_FromLong(aLedNum);
PyObject* aLedList = PyList_New(0);
for ( int aXYZ=0; aXYZ < 3; aXYZ++)
{
PyObject* aLedPosXYZ = PyFloat_FromDouble(1.0);
PyList_Append(aLedList, aLedPosXYZ);
}
PyDict_SetItem(nLedDict, aLedNumPy, aLedList);
}
PyDict_SetItem(nRetDictPy, nToolIdPy, nLedDict);
aNumIter ++;
return nRetDictPy;
}
------------------------------
I give it to python with:
------------------------------
PyObject *aKey, *aValue;
int aPos = 0;
PyObject* aNewToolDict = createPTDict();
PyDict_Next(aNewToolDict, &aPos, &aKey, &aValue);

// DictInPython passed prior to extension
PyDict_SetItem(<DictInPython>, aKey, aValue);
------------------------------
And now, what would be a proper way to cleanup the heap?
1) Does PyDict_Clear(aNewToolDict) also decrement the ref counting for the
containing list, int, ... PyObjects?
2) Do I need to Py_CLEAR( PyObject *o) for every created PyObject?

Thanks a lot for every answer/hint.

Regards
Alexander
Nov 15 '06 #1
0 823

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Raj Batra | last post by:
Hi, I've created a dll that you can import into python. The function calls an ostringstream class. Calling this function repeatedly in python will cause a Microsoft Visual C++ Debug Library...
0
by: kanedatakeshi | last post by:
Hi folks! The problem is the following: I use Python 2.1 embedded in a C++ game engine. Some of the engines complexer objects (AI, game logic, etc.) use python classes that act as an...
14
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not...
10
by: PengYu.UT | last post by:
Hi, Maybe this is an simple question. How can I insure that the objects of a class must be allocated in the heap? Thanks, Peng
1
by: Carl J. Van Arsdall | last post by:
I'm extending Python with C, it seems as though initialization is easy enough with an init<moduleName>() function that all C extended python modules must provide that can serve as a sort of "module...
12
by: Veeru | last post by:
Hi, Can anyone tell me the difference between heap memory and stack stack both physically and fundamentally. It would be a real favour. Regards, Veeru
1
by: Alexander Eisenhuth | last post by:
Hi, I'm near the ground and need help. I'm building a multithreaded extension with boost.python. python extension ----------------------------------------------------- import extension
11
by: Andy Watson | last post by:
I have an application that scans and processes a bunch of text files. The content I'm pulling out and holding in memory is at least 200MB. I'd love to be able to tell the CPython virtual machine...
0
by: larrye1428 | last post by:
(I started researching and using C# 2 days ago, so sorry if some of this is basic) After much reading and other research I have the following concerns: 1) I need a large number of 64K buffers...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
agi2029
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.