Re: To standardize Boost.Pool

Discussion in 'C++' started by Jorgen Grahn, Apr 12, 2011.

  1. Jorgen Grahn

    Jorgen Grahn Guest

    [I skip the c.l.c++.moderated crosspost]

    On Tue, 2011-04-12, 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.

    What would those benefits be, according to you? Detecting bugs (e.g.
    assert_on_heap(ptr)), or something else?


    // Jorgen Grahn <grahn@ Oo o. . .
    \X/> O o .
    Jorgen Grahn, Apr 12, 2011
    1. Advertisements

  2. Öö Tiib

    Öö Tiib Guest

    On Apr 13, 10:08 am, Phil Bouchard <> wrote:
    > On 4/12/2011 5:31 PM, Phil Bouchard wrote:
    > > On 4/12/2011 2:56 PM, Jorgen Grahn wrote:

    > >> What would those benefits be, according to you? Detecting bugs (e.g.
    > >> assert_on_heap(ptr)), or something else?

    > > Garbage collectors make use of such a function but also another memory
    > > manager I wrote called: Shifted Pointer where we can see a repetitive
    > > use of the function is_from() here:
    > >

    > After some discussion with Boost, contiguous memory pool objects could
    > represent the process' stack, data and heap segments legally.  For example:
    > struct process
    > {
    >         static pool data;
    >         static pool heap;
    >         static pool stack;
    > };
    > The default implementation of the global operator ::new could be:
    > void * operator new(size_t n) { return process::heap.malloc(n); }
    > A call to is_from() with a pointer guaranteed to be within one of the 3
    > pools will then be valid:
    > int * h = new int;
    > process::heap.is_from(h) // true
    > int s;
    > process::heap.is_from(& s) // false
    > process::stack.is_from(& s) // true
    > static int d;
    > process::heap.is_from(& d) // false
    > process::stack.is_from(& d) // false
    > process::data.is_from(& d) // true

    Please elaborate what is process::stack? On most platforms a process
    may have several threads, number of these threads often changes
    dynamically during processes lifetime and each of these threads does
    have its own stack.
    Öö Tiib, Apr 13, 2011
    1. Advertisements

  3. Miles Bader

    Miles Bader Guest

    Phil Bouchard <> writes:
    > My apologies but I forgot mentioning that we wouldn't want if_from to
    > get discredited before it upgrades to the standards. We are looking for
    > both a standard compliant version of is_from and a system specific
    > version of it.

    BTW, the name "is_from" seems very odd -- "foo->is_from (ptr)" _looks_
    like it should ask the question "foo is from ptr?", but really it means
    the opposite ("ptr is from foo?").

    A better name might be "contains": foo->contains (ptr)


    Twice, adv. Once too often.
    Miles Bader, Apr 14, 2011
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Generic Usenet Account
    Dan Pop
    Jun 8, 2004
  2. Kong Bhat
    Dietmar Kuehl
    Apr 13, 2004
  3. Kong Bhat

    Time to standardize the XML library for C/C++

    Kong Bhat, Apr 7, 2004, in forum: C Programming
    James Kuyper
    Apr 8, 2004
  4. Generic Usenet Account

    libxml needs to be tamed (standardize C/C++ XML library?)

    Generic Usenet Account, Jun 8, 2004, in forum: C Programming
    Dan Pop
    Jun 8, 2004
  5. Replies:

Share This Page