Python Forum
python call c library (about memory copy)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python call c library (about memory copy)
#1
I have a C library which will write data to memory
the function  is like
function f (char *p)
{
  memcpy(p...)
}
In python part I write as below

lib = CDLL("libtest.so")
dump= lib.f;
dump.argtypes =[c_char_p]
data =create_string_buffer(100)
dump(data)
print repr(data.raw)
but the print data is not fully right
ex:
data in c  is 100030029008....
but in python will show
\x00\x01\x00\x00\x03\x00\x00\x02\x00\t\x00\x08
some data will become strange.

Does anyone know how should I do to let python allocate a memory and pass the memory to c to write?

Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 249 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  python list out top 10 Memory utilisation mg24 0 800 Nov-20-2022, 10:51 PM
Last Post: mg24
Bug Embedded Python Memory Leaks Alexei 1 1,025 Sep-16-2022, 01:15 PM
Last Post: Alexei
  python memory rd_rakesh 1 1,645 Jul-14-2021, 11:15 AM
Last Post: jefsummers
  Copy documents to Teams using python SallySmith 0 2,379 Mar-23-2021, 04:27 AM
Last Post: SallySmith
  Windows Python Memory Scanner Awesometech 1 21,193 Oct-14-2020, 07:44 AM
Last Post: badengagen
  memory leak on embedded python in c++ asdf3721 3 3,372 Jul-16-2020, 06:33 AM
Last Post: Gribouillis
  To Copy text values to Excel using Python ksasi2k3 16 15,815 Dec-26-2019, 11:59 AM
Last Post: ashutoshdeodhar
  Call pip3 from python folder build by me call pip3 from the /usr/bin Suryavarman 3 3,684 Oct-07-2019, 10:23 PM
Last Post: Suryavarman
  Copy data from different workbooks into Master sheet with Python Fatman003 0 2,220 Aug-27-2019, 07:36 AM
Last Post: Fatman003

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020