
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