Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3642

Re: To standardize Boost.Pool

Date 2011-04-13 22:43 -0700
From Phil Bouchard <phil@fornux.com>
Newsgroups comp.lang.c++
Subject Re: To standardize Boost.Pool
References (4 earlier) <5497ee99-8d91-4412-8995-6e1ea58ded81@32g2000vbe.googlegroups.com> <4da5d23b@news.x-privat.org> <4da61a7b$1@news.x-privat.org> <4da62a76@news.x-privat.org> <Xns9EC74DE5814ACmyfirstnameosapriee@216.196.109.131>
Message-ID <4da68978@news.x-privat.org> (permalink)
Organization X-Privat.Org NNTP Server - http://www.x-privat.org

Show all headers | View raw


On 4/13/2011 9:39 PM, Paavo Helde wrote:
>
> 5.2.10/4 only says that you can cast a pointer to and back to an integral
> type large enough (if such exists). You can of course compare integers,
> but there is no guarantee that these comparisons make any sense for the
> original pointers (hint: think about x86 segmented memory model). For
> comparing pointers they must point to elements inside the same array (or
> immediately past the array) and there is no such easy way to work around
> this limitation.

The C standards actually define integer types called "intptr_t" in 
"cstdint" capable of holding object pointers (7.18.1.4).  The following 
version could then be perfectly portable:

bool is_from(const char* p)
{
     return reinterpret_cast<intptr_t>(buffer)<= 
reinterpret_cast<intptr_t>(p)&& reinterpret_cast<intptr_t>(p)< 
reinterpret_cast<intptr_t>(buffer + sizeof(buffer));
}

> In systems with flat address spaces the implementations indeed guarantee
> a total ordering of pointers as they were integers of a sufficiently
> large type. However, no hope to get 'long' working here, in Win64 long is
> only 32 bit and this is not going to change. Besides, it has wrong
> signedness.
>
> If Boost.Pool was standardized for process' memory areas its
> implementation would be quite implementation-specific anyway so there is
> no need to worry about such minor details like the suitable integer type,
> if such is needed at all. For example, in some x86 segmented memory
> models one could tell the type of the pointer just by looking at its
> segment selector, no address range comparisons needed.

Currently is_from() invokes undefined behavior with a false statement. 
This makes the utility useless unless it is reimplemented or 5.7/6 
becomes less restrictive on the comparison of pointers not part of the 
same array.


Thanks,
-Phil

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

To standardize Boost.Pool  Phil Bouchard <phil@fornux.com> - 2011-04-12 07:44 -0600
  Re: To standardize Boost.Pool Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-04-12 21:56 +0000
    Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-12 17:31 -0700
      Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-13 00:08 -0700
        Re: To standardize Boost.Pool Öö Tiib <ootiib@hot.ee> - 2011-04-13 08:28 -0700
          Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-13 09:41 -0700
            Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-13 14:49 -0700
              Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-13 15:57 -0700
                Re: To standardize Boost.Pool Paavo Helde <myfirstname@osa.pri.ee> - 2011-04-13 23:39 -0500
                Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-13 22:43 -0700
                Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-13 22:53 -0700
                Re: To standardize Boost.Pool Miles Bader <miles@gnu.org> - 2011-04-14 15:55 +0900
                Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-14 00:15 -0700

csiph-web