Re: ctypes free memory which is allocated in C DLL

2012-10-27 Thread zlchen . ken
On Sunday, October 28, 2012 6:26:28 AM UTC+8, Nobody wrote: > On Sat, 27 Oct 2012 07:42:01 -0700, zlchen.ken wrote: > > > > > I have a DLL which written in C language, one of the function is to > > > allocate a structure, fill the members and then return the pointer of > > > the structure. >

Re: ctypes free memory which is allocated in C DLL

2012-10-27 Thread Nobody
On Sat, 27 Oct 2012 07:42:01 -0700, zlchen.ken wrote: > I have a DLL which written in C language, one of the function is to > allocate a structure, fill the members and then return the pointer of > the structure. > > After Python called this function, and done with the returned structure, > I wo

Re: ctypes free memory which is allocated in C DLL

2012-10-27 Thread Chris Angelico
On Sun, Oct 28, 2012 at 2:40 AM, Ken Chen wrote: > Yes, I agree writing a corresponding API to free the memory is the best > practice and best bet. > Sometimes, the third party API may not provide that. Then that's a majorly dangerous third party API. The only time it's safe to provide a half-on

Re: ctypes free memory which is allocated in C DLL

2012-10-27 Thread Ken Chen
After I explicitly load the msvcrt which built the DLL, things are getting function now. "ctypes.util.find_msvcrt() Windows only: return the filename of the VC runtype library used by Python, and by the extension modules. If the name of the library cannot be determined, None is returned.

Re: ctypes free memory which is allocated in C DLL

2012-10-27 Thread Chris Angelico
On Sun, Oct 28, 2012 at 1:42 AM, wrote: > Hi Guys, > > I have a DLL which written in C language, one of the function is to allocate > a structure, fill the members and then return the pointer of the structure. > > After Python called this function, and done with the returned structure, I > woul

ctypes free memory which is allocated in C DLL

2012-10-27 Thread zlchen . ken
Hi Guys, I have a DLL which written in C language, one of the function is to allocate a structure, fill the members and then return the pointer of the structure. After Python called this function, and done with the returned structure, I would like to free the returned structure. How can I achie

Re: how to free memory allocated by a function call via ctypes

2009-05-30 Thread Benjamin Peterson
Tzury Bar Yochay gmail.com> writes: > > My question is how do I free the memory allocated when I call this > function using ctypes The return type of ctypes.create_string_buffer() will call free() when it is garbage collected. -- http://mail.python.org/mailman/listinfo/python-list

how to free memory allocated by a function call via ctypes

2009-05-30 Thread Tzury Bar Yochay
Hi, Suppose I have the following function char *generateMessage(char *sender, char *reciever, char *message) ; now in c I would normally do char *msg = generateMessage(sender, reciever, message); // do something free(msg); My question is how do I free the memory allocated when I call this funct

Re: Free Memory

2008-05-11 Thread Gabriel Genellina
En Sun, 11 May 2008 01:06:13 -0300, Patrick Mullen <[EMAIL PROTECTED]> escribió: > Yeah I don't know much about locals or globals. I've never used them > before, just know they are there. But anyway, to illustrate what I meant by > the interesting behavior, here is the output (and sorry for it b

Re: Free Memory

2008-05-10 Thread Patrick Mullen
Yeah I don't know much about locals or globals. I've never used them before, just know they are there. But anyway, to illustrate what I meant by the interesting behavior, here is the output (and sorry for it being so long): IDLE 2.6a2 >>> globals() {'__builtins__': , '__name__': '__main__', '__d

Re: Free Memory

2008-05-10 Thread Gabriel Genellina
27;t understand you... > It did have the effect that is asked for, although there may be more > unintended consequences. Also if any objects are attached to any of the > builtins I expect they will still be around. Your code removes all direct references to objects from the current modu

Re: Free Memory

2008-05-09 Thread Patrick Mullen
I had some very interesting results with this code to do what is asked: for key in globals().keys(): del globals()[key] for key in locals().keys(): del locals()[key] It might be better to reverse the two steps, I didn't give it much thought. Anyway, when this is done, all of the builtins

Re: Free Memory

2008-05-09 Thread Christian Heimes
Dark Wind schrieb: > Hi, > > How can I free all the memory in python by deleting all variables. I am > looking for the equivalent of 'clear' from Matlab. > > I know del x deletes a variable x, but it doesn't free all the available > memory. del doesn't free an object. It only removes one referen

Re: Free Memory

2008-05-08 Thread Ian Kelly
On Thu, May 8, 2008 at 6:30 PM, Dark Wind <[EMAIL PROTECTED]> wrote: > Hi, > > How can I free all the memory in python by deleting all variables. I am > looking for the equivalent of 'clear' from Matlab. > > I know del x deletes a variable x, but it doesn't free all the available > memory. I don't

Free Memory

2008-05-08 Thread Dark Wind
Hi, How can I free all the memory in python by deleting all variables. I am looking for the equivalent of 'clear' from Matlab. I know del x deletes a variable x, but it doesn't free all the available memory. Thank you -- http://mail.python.org/mailman/listinfo/python-list

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-29 Thread M�ta-MCI \(MVP\)
Hi! I've send the soft. But, I have no news ; good news? @+ Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

RE: How to free memory ( ie garbage collect) at run time with Python2.5.1(windows)

2007-08-28 Thread Delaney, Timothy (Tim)
Alex Martelli wrote: > rfv-370 <[EMAIL PROTECTED]> wrote: > >> have made the following small test: >> >> Before starting my test my UsedPhysicalMemory(PF): 555Mb >> > tf=range(0,1000)PF: 710Mb ( so 155Mb for my List) > tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaini

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-28 Thread Bruno Desthuilliers
Alex Martelli a écrit : > rfv-370 <[EMAIL PROTECTED]> wrote: (snip) >> So how can I force Python to clean the memory and free the memory that >> is not used? > > On Windows, with Python 2.5, I don't know of a good approach (on Linux > and other Unix-like systems I've used a strategy based on fork

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-28 Thread Francesco Guerrieri
On 8/27/07, Peter Otten <[EMAIL PROTECTED]> wrote: > Peter Otten wrote: > > > Alex Martelli wrote: > > > >> Integer objects that are once generated are kept around in a "free list" > >> against the probability that they might be needed again in the future (a > > > > Python 2.5.1 (r251:54863, May 2

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread M�ta-MCI \(MVP\)
Aïe! gmail said : "illegal attachment" (because .exe?) I will try to send a zipped-file... @+ Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread M�ta-MCI \(MVP\)
Re! Sended by direct (private) e-mail @+ Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Peter Otten
Peter Otten wrote: > Alex Martelli wrote: > >> Integer objects that are once generated are kept around in a "free list" >> against the probability that they might be needed again in the future (a > > Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) > [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Peter Otten
Alex Martelli wrote: > Integer objects that are once generated are kept around in a "free list" > against the probability that they might be needed again in the future (a Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "cred

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Marc 'BlackJack' Rintsch
ndard library is. And even a `free()` in the C standard library doesn't guarantee that memory is given back to the OS and reported as free memory again. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread MC
Hi! For windows, I had a soft for this (reduce_memory.exe). Sorry, it's not write with Python. If you want, I will give a URL for download it. -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Alex Martelli
rfv-370 <[EMAIL PROTECTED]> wrote: > have made the following small test: > > Before starting my test my UsedPhysicalMemory(PF): 555Mb > > >>>tf=range(0,1000)PF: 710Mb ( so 155Mb for my List) > >>>tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaining 117Mb is > >>>not freed?) del

How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread rfv-370
have made the following small test: Before starting my test my UsedPhysicalMemory(PF): 555Mb >>>tf=range(0,1000)PF: 710Mb ( so 155Mb for my List) >>> tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaining 117Mb is not >>> freed?) >>> del tfPF: 672Mb (u

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-26 Thread Grant Edwards
On 2007-04-26, Martin v. Löwis <[EMAIL PROTECTED]> wrote: >> I'm a bit fuzzy on this, but I don't think there _is_ a >> practical way to "return memory to the OS" in many OSes. > > That's not true at all. Most C libraries these days manage > to return memory to the operating system. [...] Thanks

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-26 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: > Our (python-)macro uses massively nested loops which are unfortunately > necessary. These loops perform complex calculations in this commercial > tool. To give you a quick overview how long this macros runs: > > The outer loop takes 5-7 hours for one cycle. Each cycle cr

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-26 Thread Martin v. Löwis
> The moment I close the application that launched the macro, my > ressources get freed. > > So is there a way to free my memory inside my nested loops? Yes. Most likely, it is your algorithm itself which is flawed (not Python, not the application that embeds Python): You keep, most likely, refer

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-26 Thread Martin v. Löwis
> I'm a bit fuzzy on this, but I don't think there _is_ a > practical way to "return memory to the OS" in many OSes. That's not true at all. Most C libraries these days manage to return memory to the operating system. On Win32 (which the OP is most likely to use), the operating system offers the

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-26 Thread TimC
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Maybe delegating the actual processing to an external python > process you feed through the macro might work. Thanks for the idea. I'll check it out soon and will report about possible improvements. -- http://mail.python.org/mailman/listinfo/pytho

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-26 Thread Paul McGuire
You might try looking at references between objects, especially if there are any cyclic refs. For instance, if you have a data structure in which child nodes have back refs to their parents, try changing these to use weakref's. This may help the garbage collector to better reclaim discarded objec

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Charles Sanders
Grant Edwards wrote: > Assuming the python interpreter free()s the memory, my > understanding is that on Unixes the memory is returned to the > pool used by malloc(), but is not returned to the OS since > there isn't a practical way to ensure that the memory at the > "end" of the data segment is no

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Diez B. Roggisch
TimC schrieb: > Donald 'Paddy' McCarthy <[EMAIL PROTECTED]> wrote > >> Could you split the program into one handling the outer loop and >> calling another program, with data transfer, to handle the inner >> loops? >> >> - Paddy. > > I'm afraid this isn't possible, because the python macro is call

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread TimC
Donald 'Paddy' McCarthy <[EMAIL PROTECTED]> wrote > Could you split the program into one handling the outer loop and > calling another program, with data transfer, to handle the inner > loops? > > - Paddy. I'm afraid this isn't possible, because the python macro is called and started from within

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Steven Howe <[EMAIL PROTECTED]> wrote: > Interesting questions. What happens when an object is 'cleaned' up by > using the 'del' command. Does the memory space stay in the python > process, get handed back to the OS, or some combination of both? > I remember 'C' on

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Grant Edwards
On 2007-04-25, Steven Howe <[EMAIL PROTECTED]> wrote: >> I'm a bit fuzzy on this, but I don't think there _is_ a >> practical way to "return memory to the OS" in many OSes. For >> example in Unix the C library uses the sbrk() call to increase >> the size of the data segment when additional memory

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Donald 'Paddy' McCarthy
[EMAIL PROTECTED] wrote: > So I read quite a few things about this phenomenon in Python 2.4.x but > I can hardly believe that there is really no solution to my problem. > > We use a commercial tool that has a macro functionality. These macros > are written in python. So far nothing extraordinary.

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Steven Howe
Grant Edwards wrote: > On 2007-04-25, Chris Mellon <[EMAIL PROTECTED]> wrote: > > >> "Returning memory to the OS" doesn't affect exhaustion of your virtual >> address space. More likely, your nested loops are just creating more >> objects than is possible to hold within a single process. >>

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Grant Edwards
On 2007-04-25, Chris Mellon <[EMAIL PROTECTED]> wrote: > "Returning memory to the OS" doesn't affect exhaustion of your virtual > address space. More likely, your nested loops are just creating more > objects than is possible to hold within a single process. I'm a bit fuzzy on this, but I don't t

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Chris Mellon
On 25 Apr 2007 15:04:59 GMT, TimC <[EMAIL PROTECTED]> wrote: > Larry Bates <[EMAIL PROTECTED]> wrote: > > > Let's see for this I need to get out my crystal ball... > > > > If it is a commercial application, you should contact their tech > > support for a solution. The problem isn't specifically a

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread TimC
Larry Bates <[EMAIL PROTECTED]> wrote: > Let's see for this I need to get out my crystal ball... > > If it is a commercial application, you should contact their tech > support for a solution. The problem isn't specifically a Python > problem but rather an implementation problem with their app. >

Re: Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Larry Bates
[EMAIL PROTECTED] wrote: > So I read quite a few things about this phenomenon in Python 2.4.x but > I can hardly believe that there is really no solution to my problem. > > We use a commercial tool that has a macro functionality. These macros > are written in python. So far nothing extraordinary.

Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread Durumdara
Hi! I got same problem with Lotus Domino + Python. The lotus COM objects are not freed, so I get out from memory. I solve this problem with a little trick: I make two py applications. The first is call the second as like another application. The first is put some work to the seconds datadir. Wh

Python not giving free memory back to the os get's me in real problems ...

2007-04-25 Thread leuchte
So I read quite a few things about this phenomenon in Python 2.4.x but I can hardly believe that there is really no solution to my problem. We use a commercial tool that has a macro functionality. These macros are written in python. So far nothing extraordinary. Our (python-)macro uses massively

Re: When to free memory for C wrapper?

2005-10-13 Thread Java and Swing
One other thing, I was reading about Py_DECREF...and I see it says "A safe approach is to always use the generic operations (functions whose name begins with "PyObject_", "PyNumber_", "PySequence_" or "PyMapping_"). These operations always increment the reference count of the object they return. T

When to free memory for C wrapper?

2005-10-13 Thread Java and Swing
I have been posting lately about writing a C wrapper so Python can access my C functions. In my wrapper function I have something like... static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { PyObject *data; char *result; long *d; PyArg_ParseTuple(args, "O:wrap_doStuff"