Boost logo

Boost :

Subject: Re: [boost] [interprocess] sharing memory between 32 bit and 64 bit Windows processes
From: Arno Schödl (aschoedl_at_[hidden])
Date: 2011-02-24 09:10:34


Hello Ion,

> Differentiating "shared distances" from other types is easy. Pointer
> arithmetics/function parameters, etc. can create temporary pointers with
> point from stack to shared memory and this distance will be different in
> 32 bit (max. 32 bit distance) and 64 systems (max. 64 bit distance!).
> The pointer type is the same, so I'm afraid option 3 is not possible.

> Option 2 suffers from the same problem. You can make pointers 32 bit but
> again 32 bit distance from stack to shared memory might be too short in
> 64 bit environments.

> For options 1, the OS won't let you allocate/connect to memory bigger
> than 32 bit limits, so you will get an error when connecting/creating
> such shared memory.

Option 1: Say the requested size is 0x101000000 (4GB+16MB), for example. 32 bit OS would truncate that to 0x1000000 and all allocation/memory mapping calls would succeed (if you have 16MB to spare). Other internal datastructures being 64 bit, they would be set up to show the full 4GB+16MB. This wouldn't work.

Option 3: The offset_ptr itself must be 64 bit, no question. But its size_type/difference_type do not have to be able to hold the difference between two arbitrary pointers, just between two pointers to the same memory block, which is max 32 bit:

C++0x draft http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3225.pdf:

5.7.6

When two pointers to elements of the same array object are subtracted, the result is the difference of the
subscripts of the two array elements. ... Unless both pointers point to elements of the same array object, or
one past the last element of the array object, the behavior is undefined.

18.2 Types:

5 The type ptrdiff_t is an implementation-defined signed integer type that can hold the difference of two
subscripts in an array object, as described in 5.7.
6 The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size
in bytes of any object.

Likewise, in 20.2.5 Allocators:

X::size_type

a type that can represent the
size of the largest object in the
allocation model.

X::difference_type

a type that can represent the
difference between any two
pointers in the allocation
model.

The difference_type definition does not explicitly refer to 5.7.6 "Unless both pointers point to elements of the same array object, ... the behavior is undefined.", but I think that is intended.

What do you think?

Arno

--
Dr. Arno Schödl | aschoedl_at_[hidden]
Technical Director
think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany
http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091
Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk