By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,955 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,955 IT Pros & Developers. It's quick & easy.

Very slow file mapping?

P: n/a
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,`- `..-`
\ .. \\ |`-'|`-, /
\\\\\\\) | |`-'/.'/
\)\)\\ `-' `-'
`

Nov 5 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 5 Nov, 10:38, kid joe <spamt...@spamtrap.invalidwrote:
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
Nov 5 '08 #2

P: n/a
kid joe wrote:
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
Nov 5 '08 #3

P: n/a
jacob navia wrote:
kid joe wrote:
>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 ...
>
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.
Nov 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.