Shared memory
Xavier PILLONS -- 100335.221@compuserve.com
Thursday, September 05, 1996
Environment: VC4.2, Win95, NT 3.51
I would like to allocate dynamically classes in shared memory used by Dll InProc
Server. How doing this ?
I know that I can use #pragma to define shared data segments, but this is for
global variables.
May I use memory mapped file ? If so, how ?
All tips and suggestions would be appreciate.
Xavier Pillons
Software Engineer
SETE Inc.
Tomasz Pawlowski -- tomasz@ashtech.COM
Thursday, September 05, 1996
Allocate memory using memory mapped files and then use "placement new"
to construct your class at specified address. Something like this:
ptr = pointer to mapped memory
T *TObject = new ( ptr ) T;
Tomasz
tomasz@ix.netcom.com
tomasz@ashtech.com
______________________________ Reply Separator _________________________________
Subject: Shared memory
Author: mfc-l@netcom.com at smtp-ccmail
Date: 9/5/96 7:49 AM
Environment: VC4.2, Win95, NT 3.51
I would like to allocate dynamically classes in shared memory used by Dll InProc
Server. How doing this ?
I know that I can use #pragma to define shared data segments, but this is for
global variables.
May I use memory mapped file ? If so, how ?
All tips and suggestions would be appreciate.
Xavier Pillons
Software Engineer
SETE Inc.
Xavier PILLONS -- 100335.221@compuserve.com
Monday, September 09, 1996
I've tried to do what you suggest, but it is not possible. So I
re-write the new and delete operator for the class TObject to use
memory mapped file. But this work fine if this class don't use others
static classes. If I use a CMap in TObject, I can't tell CMap to use
memory mapped files.
So how using shared memory with dynamic classes like map, list, CString ...?
Xavier Pillons
Software Engineer
SETE Inc.
>
>De : "Tomasz Pawlowski"[COMPUSERVE:INTERNET:tomasz@ashtech.COM]
>Date : vendredi 6 septembre 1996 06:31
>A : INTERNET:MFC-L@NETCOM.COM
>Objet : Re: Shared memory
>
>
> Allocate memory using memory mapped files and then use "placement new"
> to construct your class at specified address. Something like this:
>
> ptr = pointer to mapped memory
> T *TObject = new ( ptr ) T;
>
> Tomasz
>
> tomasz@ix.netcom.com
> tomasz@ashtech.com
Jerry Coffin -- jcoffin@taeus.com
Wednesday, September 11, 1996
At 07:49 AM 9/5/96 EDT, you wrote:
>Environment: VC4.2, Win95, NT 3.51
>
>I would like to allocate dynamically classes in shared memory used by Dll
>InProc Server. How doing this ?
There are basically two different ways to do this. One possibility is to
manually allocate the shared memory by the usual method (MapViewOfFile,
passing -1 as the file handle) and then do a placement new in that memory.
The other possibility is to override new() for the class instead. This
encapsulates placing the class in shared memory into the class itself, and
other code doesn't have to worry about it.
Generally the decision as to which method to use is fairly easy: if it's a
characteristic of the class that all its instances will always be in shared
memory, then override new() in the class to ensure that. If the class can
be placed in shared memory or not, depending on the situation, then
placement new is the way to go. If you're going to use the class in shared
memory a great deal, it may be worth deriving a new class to override new()
and make it a characteristic of the class.
Xavier PILLONS -- 100335.221@compuserve.com
Friday, September 13, 1996
Jerry Coffin, at 12 Sep 1996 09:33:08 (PDT) wrote:
>At 07:49 AM 9/5/96 EDT, you wrote:
>>
>>Environment: VC4.2, Win95, NT 3.51
>>I would like to allocate dynamically classes in shared memory used by Dll
>>InProc Server. How doing this ?
>
>There are basically two different ways to do this. One possibility is to
>manually allocate the shared memory by the usual method (MapViewOfFile,
>passing -1 as the file handle) and then do a placement new in that memory.
>
>The other possibility is to override new() for the class instead. This
>encapsulates placing the class in shared memory into the class itself, and
>other code doesn't have to worry about it.
>
>Generally the decision as to which method to use is fairly easy: if it's a
>characteristic of the class that all its instances will always be in shared
>memory, then override new() in the class to ensure that. If the class can
>be placed in shared memory or not, depending on the situation, then
>placement new is the way to go. If you're going to use the class in shared
>memory a great deal, it may be worth deriving a new class to override new()
>and make it a characteristic of the class.
Ok for overriding new() in the class, but if I want to use a collection or a map
of this class, how using shared memory with maps ? And if my class use CString
or other dynamic classes, how using shared memory for them, does I need to
override new() for each classes used in the principal class ?
Xavier Pillons 33 01 41 39 17 07
Software Engineer 100335.221@compuserve.com
SETE Inc.
Jerry Coffin -- jcoffin@taeus.com
Sunday, September 15, 1996
At 04:28 AM 9/13/96 EDT, you wrote:
[ wanting to put classes into shared memory... ]
>Ok for overriding new() in the class, but if I want to use a collection or
a map
>of this class, how using shared memory with maps ? And if my class use
>CString or other dynamic classes, how using shared memory for them, does I
>need to override new() for each classes used in the principal class ?
Most (all?) of the STL collections have you pass an allocator object to them
that they use to allocate/free memory for the objects in the collection.
This should the right place to handle putting the collection into shared memory.
| Вернуться в корень Архива
|