Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32282

Re: ctypes free memory which is allocated in C DLL

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'function,': 0.07; 'api': 0.09; 'python': 0.09; 'structure,': 0.09; 'subject:ctypes': 0.09; 'language,': 0.11; 'library': 0.15; 'allocates': 0.16; 'dll,': 0.16; 'exposes': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guys,': 0.16; 'oct': 0.16; 'structure.': 0.16; 'subject:which': 0.16; 'wrote:': 0.17; 'pointer': 0.17; 'memory': 0.18; 'written': 0.20; 'received:209.85.214.174': 0.21; 'work.': 0.23; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'wrote': 0.26; 'am,': 0.27; 'dll': 0.27; 'message-id:@mail.gmail.com': 0.27; 'interface': 0.27; "doesn't": 0.28; 'returned': 0.30; 'function': 0.30; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'free': 0.61; 'basically,': 0.84; 'safe.': 0.93; 'subject:free': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=JEBsk9d6Lg2ACyV8F/rRV0xzzv60vH54E+Bf3n99v+A=; b=cxdDNHaosLoBJ5ItsX7X1pEMi/KiHzMuqHmykalSkafMDyP+j/+h3BDBF51wUAOtxy VZtx21DL0yCElsiN8kD1x2DGU2cDFHZiQXXZ2wO1Dy3DN3S6tPv+RGG9HNfgHquhhhWX zaCKUtqjsG/Zm9hqCPwcV2PR/REsjBC8Ru1h6R0ZanzKfPqiOr3tezuawhRFnrk5y/lr XKYAG0/lnjB50kOsWqqtZyU6kqDZA1JV4M/MHnPe3vUie/+kRsCYmxYWncKtFHX1XDuu Z7x0aFilmW5kDmad5Uivy4wNoPilkjXIRWCGcKBeFSCTbYhdVImae6fBE0PmYWQYPcXu heLg==
MIME-Version 1.0
In-Reply-To <e5ab59f8-da39-4d50-bca2-63a5f5ec0cc2@googlegroups.com>
References <e5ab59f8-da39-4d50-bca2-63a5f5ec0cc2@googlegroups.com>
Date Sun, 28 Oct 2012 01:56:47 +1100
Subject Re: ctypes free memory which is allocated in C DLL
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2940.1351349811.27098.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351349811 news.xs4all.nl 6978 [2001:888:2000:d::a6]:45906
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32282

Show key headers only | View raw


On Sun, Oct 28, 2012 at 1:42 AM,  <zlchen.ken@gmail.com> 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 would like to free the returned structure. How can I achieve this ? Basically, I tried that I wrote a corresponding free interface in the DLL, it works, but calling the libc.free in Python doesn't work.

As a general rule, you should always match your allocs and frees. Use
the same library to free the memory as was used to allocate it.
Nothing else is safe. If your DLL exposes an API that allocates
memory, your DLL should expose a corresponding API to free it. So what
you have is the best way :)

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

ctypes free memory which is allocated in C DLL zlchen.ken@gmail.com - 2012-10-27 07:42 -0700
  Re: ctypes free memory which is allocated in C DLL Chris Angelico <rosuav@gmail.com> - 2012-10-28 01:56 +1100
    Re: ctypes free memory which is allocated in C DLL Ken Chen <zlchen.ken@gmail.com> - 2012-10-27 08:40 -0700
      Re: ctypes free memory which is allocated in C DLL Chris Angelico <rosuav@gmail.com> - 2012-10-28 07:26 +1100
    Re: ctypes free memory which is allocated in C DLL Ken Chen <zlchen.ken@gmail.com> - 2012-10-27 08:40 -0700
  Re: ctypes free memory which is allocated in C DLL Nobody <nobody@nowhere.com> - 2012-10-27 23:26 +0100
    Re: ctypes free memory which is allocated in C DLL zlchen.ken@gmail.com - 2012-10-27 19:05 -0700

csiph-web