shared memory pointer

Tim tec at knology.net
Mon Sep 10 17:21:24 CEST 2007


On Sep 10, 10:11 am, Tim Golden <m... at timgolden.me.uk> wrote:
> Tim wrote:
> > Hello Everyone,
>
> > I am getting shared memory in python using the following.
>
> > szName = c_char_p(name)
> > hMapObject = windll.kernel32.CreateFileMappingA(INVALID_HANDLE_VALUE,
> >             None, PAGE_READONLY, 0, TABLE_SHMEMSIZE, szName)
> > if (hMapObject == 0):
> >             print "OpenKey: Could not open name file mapping object"
> >             raise WinError()
>
> > self.pData = windll.kernel32.MapViewOfFile(hMapObject,
> >        FILE_MAP_ALL_ACCESS, 0, 0, TABLE_SHMEMSIZE)
>
> Without answering your question directly, why not use
> the stdlib mmap module, which does exactly this for
> you behind the scenes?
>
> Docs -http://docs.python.org/lib/module-mmap.html
> Example -http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413807
>
> TJG

I saw the mmap function in the shared memory example. I had some
concern with my large memory size being written to the disk drive. I
though it might slow down my application. The reason I am writting
this new code is because the existing method using a file. I thought
shared memory would be much faster.

I have tried using the memcpy and addresses, casting, etc. Is there a
way to use memcpy with the pData returned by MapViewOfFile()?

Thanks
Tim





More information about the Python-list mailing list