Hi,
> But the problem is that by specifying the type as ctypes.c_char_p,
> ctypes will hide that pointer from you and return a Python object
> instead. I'm not sure how ctypes is doing it under the hood, but I
> suspect ctypes is doing it's own strdup of the string on conversion, and
> managing
On 6/7/20 2:25 PM, Barry wrote:
>> Does ctypes, when using restype, frees allocated memory?
>>
>> For example, will the memory allocated by "strdup" be freed after the "del"
>> statement? If not, how can I free it?
>
> See https://linux.die.net/man/3/strdup that tells you to use free() to delete
> On 7 Jun 2020, at 14:23, Miki Tebeka wrote:
>
> Hi,
>
> Does ctypes, when using restype, frees allocated memory?
>
> For example, will the memory allocated by "strdup" be freed after the "del"
> statement? If not, how can I free it?
See https://linux.die.net/man/3/strdup that tells you
On 6/7/20 7:15 AM, Miki Tebeka wrote:
> Hi,
>
> Does ctypes, when using restype, frees allocated memory?
>
> For example, will the memory allocated by "strdup" be freed after the "del"
> statement? If not, how can I free it?
I don't think so. I did a quick google search and came up with this
> Does ctypes, when using restype, frees allocated memory?
>
> For example, will the memory allocated by "strdup" be freed after the "del"
> statement? If not, how can I free it?
I've tried the following program and I'm more confused now :) Can anyone
explain the output?
---
import ctypes
Hi,
Does ctypes, when using restype, frees allocated memory?
For example, will the memory allocated by "strdup" be freed after the "del"
statement? If not, how can I free it?
---
import ctypes
libc = ctypes.cdll.LoadLibrary('libc.so.6')
strdup = libc.strdup
strdup.argtypes = [ctypes.c_char_p]