简体   繁体   中英

Can I use a single file as a buffer? I.e. write to and read from at same time

I want to have an application writing out information at the same time that a monitor is reading it. The application is "embedded" (and on Win32 XP) and so has restricted memory and I/O functionality.

The simplest way I can think to do this is by writing the data to a buffer file from the application, and then read the same file using the monitor application. The writer application is C++, and the reader is currently Python on Win32 XP.

Are there libraries to do this? Has anyone seen examples of this?

I don't want to have to use a database as I don't want to link to a database library in the applcation. Ie don't have space and may not be supported on the embedded platform.

Another way to do this is over a network connection, but I figure files are the simplest solution.

Most systems has several solutions for what you want to do, such as pipes and unix sockets. These are intended for this, unlike regular files. There are however programs that does this on regular files, and I think the clearest example of this is the unix-utility tail, which can "follow" a file.

Take a look at
http://msdn.microsoft.com/en-us/library/aa365590(VS.85).aspx

Python has a good wrapper library for win32, so anything you see there can probably be access from python.

You can use memory-mapped files, standard Python module called mmap.

What you're talking about is called "Interprocess Communication". There are lots of ways of doing this.

Using Unix pipes.

https://docs.python.org/library/pipes.html

Using sockets.

https://docs.python.org/library/socket.html

Using queues.

https://docs.python.org/library/queue.html

Any of these is better than file I/O.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM