how to create an external string when binding C to Python?

S

Simon

I'd like to make a C memory buffer available inside Python via the Python C/API without copying that memory into Python. How to do this? I've read [1]but it's not clear that this functionality exists. In javascript it's possible using String::NewExternal() [2].

"Creates a new external string using the ASCII data defined in the given resource.

When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource."

[1] https://docs.python.org/2/c-api/buffer.html
[2] http://izs.me/v8-docs/classv8_1_1String.html#a07c47bf675b802c550984fa24511a589
 
M

Mark Lawrence

I'd like to make a C memory buffer available inside Python via the Python C/API without copying that memory into Python. How to do this? I've read [1] but it's not clear that this functionality exists. In javascript it's possible using String::NewExternal() [2].

"Creates a new external string using the ASCII data defined in the given resource.

When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource."

[1] https://docs.python.org/2/c-api/buffer.html
[2] http://izs.me/v8-docs/classv8_1_1String.html#a07c47bf675b802c550984fa24511a589

Does this help
http://jakevdp.github.io/blog/2014/05/05/introduction-to-the-python-buffer-protocol/
?

Also note that the Python 3 buffer protocol differs from that of Python
2, so make sure that you check out PEP 3118 that's referenced in the
above link.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top