From: Phil Bouchard Newsgroups: comp.std.c++ Subject: Re: To standardize Boost.Pool Date: Thu, 14 Apr 2011 13:10:41 CST Organization: X-Privat.Org NNTP Server - http://www.x-privat.org Lines: 51 Sender: std-cpp-request@vandevoorde.com Approved: stephen.clamage@oracle.com Message-ID: <4da63271@news.x-privat.org> References: <4da38cde@news.x-privat.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed To: undisclosed-recipients:; Return-Path: X-Original-Date: Wed, 13 Apr 2011 16:31:53 -0700 X-Submission-Address: std-c++-submit@vandevoorde.com Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!news.ecp.fr!news.alt.net Xref: x330-a1.tempe.blueboxinc.net comp.std.c++:103 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(buffer)<= reinterpret_cast(p)&& reinterpret_cast(p)< reinterpret_cast(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 ]