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


Groups > comp.std.c++ > #103

Re: To standardize Boost.Pool

From Phil Bouchard<phil@fornux.com>
Newsgroups comp.std.c++
Subject Re: To standardize Boost.Pool
Date 2011-04-14 13:10 -0600
Organization X-Privat.Org NNTP Server - http://www.x-privat.org
Message-ID <4da63271@news.x-privat.org> (permalink)
References <4da38cde@news.x-privat.org>

Show all headers | View raw


On 4/12/2011 12:10 PM, Phil Bouchard wrote:
>
>  Boost.Pool provides an is_from() member function that does a simple range
>  checks of the heap memory pages and returns whether a pointer is part of
>  the
>  pool or not. This is a very useful function which I think should be part of
>  the standards because it could be used for the global pool as well; i.e.
>  the
>  one used by operator ::new and ::delete. The benefits for memory management
>  of knowing whether an object resides on the heap or stack outweigh the
>  costs
>  of having to pollute the global namespace.

is_from() actually invokes undefined behavior if its parameter is a
pointer referring to an element outside of the pool according to 5.7.6.
  If the pointer was to be casted to the largest integer type available
on the system then a range check would be valid for that system.  For
example:

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

It's "implementation defined" but perhaps a reinterpret_cast of a
pointer to a long integer could be guaranteed to be valid by the
standards, long being the greatest integer available on a system.

Because otherwise the current implementation of is_from would then be
useless if a false statement invokes undefined behavior.  The current
implementation of is_from can be found here:
http://www.boost.org/doc/libs/1_46_1/boost/pool/pool.hpp

is_from and a heap pool are frequent utilities used by memory managers
such a garbage collectors and Shifted Pointer.  An overview of Shifted
Pointer can be found at:
http://www.fornux.com/personal/philippe/devel/shifted_ptr/libs/smart_ptr/doc/overview.html


Regards,
-Phil


-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

To standardize Boost.Pool  Phil Bouchard <phil@fornux.com> - 2011-04-12 13:10 -0600
  Re: To standardize Boost.Pool Phil Bouchard<phil@fornux.com> - 2011-04-14 13:10 -0600
    Re: To standardize Boost.Pool  Phil Bouchard <phil@fornux.com> - 2011-04-14 17:18 -0600
      Re: To standardize Boost.Pool  "Bo Persson" <bop@gmb.dk> - 2011-04-17 01:33 -0600

csiph-web