Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting the size of the shared memory object.

1,058 views
Skip to first unread message

Sela

unread,
Jul 1, 2007, 10:28:00 AM7/1/07
to
To create a shared memory I use the CreateFileMapping() API with an
INVALID_HANDLE_VALUE as the file handle. To open it from another process I
use OpenFileMapping() API giving it the name of the file mapping object. From
this other process I could not find a way to get the size of this shared
memory. Is there a way to query the shared memory for this information?

Thanks,
Sela.

Scott McPhillips [MVP]

unread,
Jul 1, 2007, 10:38:50 AM7/1/07
to

No, I don't think there is any API for that. What you can do is have
the creating process store the size at a known offset in the shared
memory so the second process can read it.

--
Scott McPhillips [MVP VC++]

Gary Chanson

unread,
Jul 1, 2007, 5:29:49 PM7/1/07
to

"Sela" <Se...@discussions.microsoft.com> wrote in message
news:0A87590B-54F7-4CEA...@microsoft.com...

Not really, but you might be able to make a good guess based on
VirtualQuery. It's better to either know that it's a fixed size or use
Scott's suggestion.

--

- Gary Chanson (Windows SDK MVP)
- Abolish Public Schools


Kellie Fitton

unread,
Jul 1, 2007, 7:59:35 PM7/1/07
to


Hi,

The following weblinks will provide additional pointers
about Managing Memory-Mapped Files and memory limits:

http://msdn2.microsoft.com/en-us/library/ms810613.aspx

http://msdn2.microsoft.com/en-us/library/aa366778.aspx

Kellie.


Sela

unread,
Jul 2, 2007, 1:36:01 AM7/2/07
to

"Sela" wrote:


Thanks for all the answers guys. I needed it to create a general purpose
class for shared memory, but if there's no way, there's no way.


Arkady Frenkel

unread,
Jul 2, 2007, 2:16:09 AM7/2/07
to
You can write the function define the size by reading from mapped file with
increasing length. If it fail on exception you can deside that file have
that size-1 length.
Arkady

"Sela" <Se...@discussions.microsoft.com> wrote in message

news:228E64C6-4151-4B1F...@microsoft.com...

Sela

unread,
Jul 2, 2007, 3:26:03 AM7/2/07
to

"Arkady Frenkel" wrote:

That will take too long (CPU time that is). I'll just let my users know
about this problem via the class documentation and they'll decide them selves
the way to solve this problem that fits their application the most.

Scherbina Vladimir

unread,
Jul 2, 2007, 11:49:58 AM7/2/07
to
Actually, the problem is not so critical.

The size of shared object can be represented as DWORD written at the
begining of the file (in cases of big amount of data use QWORD). Each client
that wants to use shared memory objects reads that value, obtains offset to
the end of shared memory and then can write any data to it, of course client
should update the length after adding the data to file. Also, do not forget
about syncronization. Usually, named objects are used to syncronyze access
to MMF.

--
Vladimir, Windows SDK MVP


"Sela" <Se...@discussions.microsoft.com> wrote in message

news:740BFF5D-67BC-4B07...@microsoft.com...

0 new messages