Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:04:40+00:00 2026-06-01T19:04:40+00:00

I have a C application that embeds the Python 2.7 interpreter. At some point

  • 0

I have a C application that embeds the Python 2.7 interpreter. At some point in my program, a potentially large string (char*) is generated and needs to be processed by some Python code. I use PyObject_CallFunction to call the Python function and pass the string as an argument. This Python function then uses the multiprocessing library to analyze the data in a separate process.

Passing the string to the Python function will create a copy of the data in a Python str object. I tried to avoid this extra copy by passing a buffer object to the Python function. Unfortunately, this generates an error in the multiprocessing process during unpickling:

TypeError: buffer() takes at least 1 argument (0 given)

It seems as though buffer objects can be pickled, but not unpickled.

Any suggestions on passing the char* from C to the multiprocessing function without making an extra copy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:04:41+00:00Added an answer on June 1, 2026 at 7:04 pm

    Approach that worked for me:

    Before you create your big C string, allocate memory for it using Python:

    PyObject *pystr = PyString_FromStringAndSize(NULL, size);
    char *str = PyString_AS_STRING(pystr);
    /* now fill <str> with <size> bytes */
    

    This way, when the time comes to pass it to Python, you don’t have to create a copy:

    PyObject *result = PyObject_CallFunctionObjArgs(callable, pystr, NULL);
    /* or PyObject_CallFunction(callable, "O", pystr) if you prefer */
    

    Note that you shouldn’t modify the string once this is done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ application that embeds the Python interpreter. It calls PyImport_Import to
I have a small shell application that embeds Tcl to execute some set of
I have a small application which embeds webbrowser controls. In that application I have
I'll be quick: I have a C++ application that embeds Lua. Until now I
I have a Silverlight application that I need to embed some less-than-common fonts in.
I have a web application that uses jQuery to load some sound effect on
I have an application that uses Flash for the GUI and Python for the
So I have an application that embeds a Navigation Controller inside a Tab Bar
I have a C++ application that embeds Internet Explorer as a WebBrowser control. The
We've made an application that embeds some web content, which has been approved before.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.