473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

mmap and ctypes

Hi all,

I have a mmap and a data structure in it. I know the structure's
location in the mmap and what structure it is. It has a ctypes
definition.

I want to initialize a ctypes object to point to a part of the mmap.

Here is my attempt:
>>b
<mmap.mmap object at 0x009FEDB8>
>>c= ctypes.pointer( b )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\programs\Python25\lib\ctypes\__init__.py", line 318, in
pointer
return POINTER(type(inst))(inst)
File "C:\programs\Python25\lib\ctypes\__init__.py", line 262, in
POINTER
{'_type_': cls})
TypeError: _type_ must have storage info

and then use 'cast', but it fails here.

Is there some way to combine ctypes with struct.pack_into and
struct.unpack_from? Can I access the mmap's buffer directly? Could
be very handy and I'm willing to talk about the C function involved.
What kind of modification to mmapmodule would we be looking at? Does
someone want to do it with me?

I am looking at mmapmodule.c, line 75, access to the char * data
member of mmap_object. Link is here:

http://www.google.com/codesearch?hl=...s/mmapmodule.c

Aug 16 '08 #1
5 4149
Hi!

I use mmap for interchange data between Python & Autoit. For that, I
use (Autoit's side) a little DLL.
This DLL can, perhaps, be used with ctypes.

@-salutations
--
Michel Claveau

Aug 16 '08 #2
On Aug 16, 4:42*pm, "Michel Claveau - NoSpam SVP ; merci"
<noZ.sp...@ZZ.ZsvpZ.comwrote:
Hi!

I use mmap for interchange data between Python & Autoit. *For that, I
use (Autoit's side) a little DLL.
This DLL can, perhaps, be used with ctypes.

@-salutations
--
Michel Claveau
Say more-- what DLL? @-greetings
Aug 16 '08 #3
On Aug 16, 5:20*pm, castironpi <castiro...@gmail.comwrote:
On Aug 16, 4:42*pm, "Michel Claveau - NoSpam SVP ; merci"

<noZ.sp...@ZZ.ZsvpZ.comwrote:
Hi!
I use mmap for interchange data between Python & Autoit. *For that, I
use (Autoit's side) a little DLL.
This DLL can, perhaps, be used with ctypes.
@-salutations
--
Michel Claveau

Say more-- what DLL? *@-greetings
This worked to 'cast' the mmap memory block to an integer:

a= ctypesbuf.get( m, 0, ctypes.POINTER( ctypes.c_uint32 ) )

where ctypesbuf is a C extension module, and 'get' contains:

...
char* seg= map->data+ index;
PyObject* char_buf= PyObject_CallFunction( ctypesmod_cast, "IO",
seg, tp );
return char_buf;

However I find no equivalent to 'map->data' in Python.
Aug 17 '08 #4
Hi!

See here:
http://www.ponx.org/download/CD/COMdll/autoitmmap.dll

@-salutations
--
Michel Claveau

Aug 18 '08 #5
On Aug 18, 1:09*am, "Méta-MCI \(MVP\)"
<enleverlesX.X...@XmclaveauX.comwrote:
Hi!

See here:
*http://www.ponx.org/download/CD/COMdll/autoitmmap.dll

@-salutations
--
Michel Claveau
I don't see how it fits in.
Aug 21 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hao Xu | last post by:
Hi everyone! I found that if you want to write to the memory got by mmap(), you have to get the file descriptor for mmap() in O_RDWR mode. If you got the file descriptor in O_WRONLY mode, then...
4
by: Fabiano Sidler | last post by:
Hi folks! I created an mmap object like so: --- snip --- from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE fl = file('/dev/zero','rw') mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS) ---...
1
by: sjdevnull | last post by:
Hey, I'm trying to wrap GNU readline with ctypes (the Python readline library doesn't support the callback interface), but I can't figure out how to set values to a variable inside the library. ...
1
by: James T. Dennis | last post by:
I've been thinking about the Python mmap module quite a bit during the last couple of days. Sadly most of it has just been thinking ... and reading pages from Google searches ... and very little...
1
by: koara | last post by:
Hello all, i am using the mmap module (python2.4) to access contents of a file. My question regards the relative performance of mmap.seek() vs mmap.tell(). I have a generator that returns...
2
by: Neal Becker | last post by:
On linux, I don't understand why: f = open ('/dev/eos', 'rw') m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE, flags=mmap.MAP_SHARED) gives 'permission denied', but...
0
by: Kris Kennaway | last post by:
If I do the following: def mmap_search(f, string): fh = file(f) mm = mmap.mmap(fh.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ) return mm.find(string) def mmap_is_in(f, string): fh =...
0
by: Gabriel Genellina | last post by:
En Thu, 29 May 2008 19:17:05 -0300, Kris Kennaway <kris@FreeBSD.org> escribió: Looks like you should define the sq_contains member in mmap_as_sequence, and the type should have the...
5
by: castironpi | last post by:
Hi, I've got an "in-place" memory manager that uses a disk-backed memory- mapped buffer. Among its possibilities are: storing variable-length strings and structures for persistence and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.