Shared Memory via Memory-Mapped Files 
Author Message
 Shared Memory via Memory-Mapped Files

I want to use memory-mapped files to share data between an application
and a supporting DLL, both written in VB5.  I don't have a problem with
CreateFileMapping, etc., but I can't quite figure out how to determine
the current size of a user-defined type structure (which includes
strings) in order to reliably write the data from the structure to the
shared memory at one end, and read the data into the matching structure
at the other end.  I could do it with binary files, but I need the speed
of shared memory.

Any help is most gratefully appreciated.

Peter



Tue, 03 Dec 2002 03:00:00 GMT  
 Shared Memory via Memory-Mapped Files
The easiest solution that comes to mind is to use Null-ended Byte Arrays
which are of fixed length for your strings, instead of VB strings.  Should
be fairly simple to write a routine to put a string into a Byte-Array.
Fixed length VB strings may also work and be more friendly, they do have the
same size as their declared length (as per MSDN help).



Quote:
> I want to use memory-mapped files to share data between an application
> and a supporting DLL, both written in VB5.  I don't have a problem with
> CreateFileMapping, etc., but I can't quite figure out how to determine
> the current size of a user-defined type structure (which includes
> strings) in order to reliably write the data from the structure to the
> shared memory at one end, and read the data into the matching structure
> at the other end.  I could do it with binary files, but I need the speed
> of shared memory.

> Any help is most gratefully appreciated.

> Peter



Tue, 03 Dec 2002 03:00:00 GMT  
 Shared Memory via Memory-Mapped Files
Hi Peter,

You question has aroused my curiosity.  I have never used memory mapped
files, but my reading about them led me to believe that they provide the
most effective way of sharing memory between different applications.  With
separate applications there is a problem in sharing memory since each will
run in a separate and distinct memory address space.  Memory mapped files
offer a way of getting around this restriction.  However, an ActiveX DLL
runs in the same process and thread as the calling application so there is
not the same memory sharing issue at all in this case.

I obviously don't know what sort of data you want to share in memory, except
that it includes UDTs, or how much data you want to share.  However, I would
be curious to know why you feel that you cannot do this adequately with
normal VB code, for example, by storing the data in an instance of a class
in the main application and simply passing a reference to this instance to
the DLL.  I am very much  a learner, and it is in this context that I am
asking the question.

Regards,

John............

Quote:

> I want to use memory-mapped files to share data between an application
> and a supporting DLL, both written in VB5.  I don't have a problem with
> CreateFileMapping, etc., but I can't quite figure out how to determine
> the current size of a user-defined type structure (which includes
> strings) in order to reliably write the data from the structure to the
> shared memory at one end, and read the data into the matching structure
> at the other end.  I could do it with binary files, but I need the speed
> of shared memory.

> Any help is most gratefully appreciated.

> Peter



Wed, 04 Dec 2002 03:00:00 GMT  
 Shared Memory via Memory-Mapped Files
I have not yet used memory mapping, mainly because I have never yet
needed to - and and ActiveX.Exe is ideal for passing data between
Apps.

It also has the benefit that you can notify the destination App via a
Callback



Wed, 04 Dec 2002 03:00:00 GMT  
 Shared Memory via Memory-Mapped Files

Quote:
> The easiest solution that comes to mind is to use Null-ended Byte Arrays
> which are of fixed length for your strings, instead of VB strings.  Should
> be fairly simple to write a routine to put a string into a Byte-Array.
> Fixed length VB strings may also work and be more friendly, they do have
the
> same size as their declared length (as per MSDN help).

Actually, to be technically acurate, they will occupy twice their declared
length because they are still UNICODE and not ANSI.
Quote:


> > I want to use memory-mapped files to share data between an application
> > and a supporting DLL, both written in VB5.  I don't have a problem with
> > CreateFileMapping, etc., but I can't quite figure out how to determine
> > the current size of a user-defined type structure (which includes
> > strings) in order to reliably write the data from the structure to the
> > shared memory at one end, and read the data into the matching structure
> > at the other end.  I could do it with binary files, but I need the speed
> > of shared memory.

> > Any help is most gratefully appreciated.

> > Peter



Wed, 04 Dec 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Mapping variables created in VB3.0 to common/shared memory

2. Memory, Memory and more Memory

3. How to reference Memory Mapped File data directly?

4. MEMORY MAPPED FILE

5. memory mapped files?

6. Memory Mapped Files in VB

7. Using Memory Mapped Files in VB 5.0

8. Memory mapped files in VB 4.0 / Win 95 ?

9. memory mapped files

10. Memory Mapped files

11. Memory Mapped Files

12. memory mapped files

 

 
Powered by phpBB® Forum Software