Re: How to point to a global memory block from multiple apps?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jim Mack (jmack_at_mdxi.nospam.com)
Date: 12/29/04


Date: Wed, 29 Dec 2004 06:32:30 -0500

Bruno Köller wrote:
>
> How is MyArr() linked tothe memory mapped file? All I've seen till
> now is that I first have to copy an entire block of data from an
> memory mappoed file to my array memory, then to update array values
> and to copy back the array into the memory mapped file, what would
> mean that I have to run two copy processes. There might be no big
> difference between copying the entire array or only a single element
> of it, but two more copys might cost soem time, I fear.

I'm sure Olaf will give you complete details, but basically what you do
is to create an empty but correctly-sized array of the UDT that you're
using, then substitute the address of the memory mapping for the array's
data pointer. You do this in each entity that needs to access the
memory.

Interestingly, the mapping address may actually be different in each
application, but as long as it's opened by the same name, all arrays
will point to the same data.

You can keep mulitple arrays in a single mapping by allocating one block
and using offsets to adjust the pointers into it, but it's usually
simpler to keep multiple mappings, one per array.

There are cautions with this approach -- the array must stay in scope as
long as the remapping is in effect, you must restore the original data
pointer before destroying or modifying the underlying array structure,
etc.

-- 
    Jim Mack
    MicroDexterity Inc
    www.microdexterity.com


Relevant Pages

  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: High Memory Consumption of Classes and Arrays
    ... Only the array itself has overhead. ... memory as a reference type. ... > least consume 40 bytes of memory. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.language)
  • Re: OOP and C++ and C (was Re: Dennis Ritchie -- An Appreciation)
    ... different layout in memory. ... memory is one large array like structure. ... That's the fundamental abstraction that our hardware attempts to ...
    (comp.lang.c)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.mfc)