Connecting Tech Pros Worldwide Forums | Help | Site Map

Very slow file mapping?

kid joe
Guest
 
Posts: n/a
#1: Nov 5 '08
Hi

I need to share about 10 MB of data between two processes. In the first
process, I do something similar to:

HANDLE hBuffer = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE, 0, 10000000, "This is a test");
// <- Check for errors
void *buffer = MapViewOfFile(hBuffer,FILE_MAP_WRITE, 0, 0, 0);
// <- Check for errors
// <- Write something in the buffer

In the second process:

HANDLE hBuffer = OpenFileMapping(FILE_MAP_WRITE, false, "This is a
test");
// <- Check for errors
void *buffer = MapViewOfFile(hBuffer, FILE_MAP_WRITE, 0, 0, 0);
// <- Check for errors
// <- Read all the buffer

What I read is what was written, which is okay. The problem is that, in
the second process, it is about 10 (ten) times slower to read the buffer
that was allocated in the first process than to read another 10 MB
buffer allocated in the second process itself. Is it normal? Is there a
way to share memory more efficiently?

Thanks

Joe

--
.--------------------.
| |
| Good Morning.... | .--.--.
| | .; .;|;. ;.
`-------------. ,---' .;_;' `;_;.
\| ; ;' `; ;
\ ;;'.--.___.--.`;;
;-( o )=3D( o )-;
( `--' | `--' )
\| . . |/
........... . .:::::. . .______
/ . '---` . '\
.' `. .' \
| ____,.- . | `.....' | _______ |
| ,-' \ /|\'' \.-- |
| / \.'\ /,'. \. - |
| /| ` `\ / \ |
| ,/ _ '/ '\ |
,-' ,-. |o '
/ '| | | | \
/ ,/| |o | \ `
| .' | |.' |. \ \
________/ .'____|________________________||__`. `__________
( \ ) / )
'-. '-. ( .-` .-`
'-. .-'--.__. .-.__.--`-. .-`
'-..' \--' : ~`:=3D,`- `..-`
\ .. \\ |`-'|`-, /
\\\\\\\) | |`-'/.'/
\)\)\\ `-' `-'
`






Nick Keighley
Guest
 
Posts: n/a
#2: Nov 5 '08

re: Very slow file mapping?


On 5 Nov, 10:38, kid joe <spamt...@spamtrap.invalidwrote:
Quote:
I need to share about 10 MB of data between two processes. In the first
process, I do something similar to:
<snip>

standard C has no support for processes. Re-post in a platform
specific group.

--
Nick Keighley
jacob navia
Guest
 
Posts: n/a
#3: Nov 5 '08

re: Very slow file mapping?


kid joe wrote:
Quote:
Hi
>
I need to share about 10 MB of data between two processes. In the first
process, I do something similar to:
>
HANDLE hBuffer = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE, 0, 10000000, "This is a test");
// <- Check for errors
void *buffer = MapViewOfFile(hBuffer,FILE_MAP_WRITE, 0, 0, 0);
// <- Check for errors
// <- Write something in the buffer
>
In the second process:
>
HANDLE hBuffer = OpenFileMapping(FILE_MAP_WRITE, false, "This is a
test");
// <- Check for errors
void *buffer = MapViewOfFile(hBuffer, FILE_MAP_WRITE, 0, 0, 0);
// <- Check for errors
// <- Read all the buffer
>
What I read is what was written, which is okay. The problem is that, in
the second process, it is about 10 (ten) times slower to read the buffer
that was allocated in the first process than to read another 10 MB
buffer allocated in the second process itself. Is it normal? Is there a
way to share memory more efficiently?
>
Thanks
>
Joe
>
Hi Joe.
1) You open the read part with FILE_MAP_WRITE... why? If you are just
going to read it would be better to ask for read access only. If not,
the synchronization problems could bog you down.

2) You have to experiment with different setups... What about a pipe?
Or other solutions? Just look the documentation in MSDN.



--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
CBFalconer
Guest
 
Posts: n/a
#4: Nov 5 '08

re: Very slow file mapping?


jacob navia wrote:
Quote:
kid joe wrote:
>
Quote:
>I need to share about 10 MB of data between two processes. In
>the first process, I do something similar to:
>>
>HANDLE hBuffer = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
>PAGE_READWRITE, 0, 10000000, "This is a test");
>
.... snip ...
Quote:
>
1) You open the read part with FILE_MAP_WRITE... why? If you are just
going to read it would be better to ask for read access only. If not,
the synchronization problems could bog you down.
>
2) You have to experiment with different setups... What about a pipe?
Or other solutions? Just look the documentation in MSDN.
This is all off-topic on c.l.c. Find a windows newsgroup.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Closed Thread