473,597 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ 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,flo at] int:[float,float,flo at], ...}}

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_FromDou ble(1.0);
PyList_Append(a LedList, 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(aNe wToolDict, &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(aN ewToolDict) 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 829

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

Similar topics

2
2411
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 error: Debug Assertion Failed! Program: C:\Program Files\Python22\python.exe File: dbgheap.c Line: 346
0
1263
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 extension of those "parent" C++-classes. The python classes are currently loaded on demand by their "parent" C++-instances, say if an enemy gets activated and starts running. I do
14
30083
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 part of the standard, then just disregard this question. Here's some questions I'm confused about, and if you can add anything else, please do so! Is the stack limited for each program?
10
2114
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
1784
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 constructor". Can C extended python modules provide any kind module destructor, so that whenever the module is unloaded some cleanup is run? Thanks, carl
12
6214
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
1700
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
5198
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 that I need a heap of, say 300MB up front rather than have it grow as needed. I've had a scan through the archives of comp.lang.python and the python docs but cannot find a way to do this. Is this possible to configure the PVM this way? ...
0
1371
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 (as many as I can get) and they will last the life of the app. 2) These will be read/written to/from via win API's 3) They need to accessed via pointers (kept in a circular list)
0
7965
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8380
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 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...
0
8258
tracyyun
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...
0
6686
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, 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...
1
5847
isladogs
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...
0
5426
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();...
0
3881
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...
0
3923
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2399
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 we have to send another system

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.