Problem on data location.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shuisheng

    Problem on data location.

    Dear All,

    I am wondering if there is a way to know if a data is in heap? My case
    is like this:

    I have a data and want to shallowly copy it into an object (just pass
    its head pointer). If the data is in heap, the object will take charge
    of deleting it.

    Thanks,

    Shuisheng

  • Jens Theisen

    #2
    Re: Problem on data location.

    "shuisheng" <shuisheng75@ya hoo.comwrites:
    Dear All,
    >
    I am wondering if there is a way to know if a data is in heap? My case
    is like this:
    >
    I have a data and want to shallowly copy it into an object (just pass
    its head pointer). If the data is in heap, the object will take charge
    of deleting it.
    There is no portable way of detecting whether an objects was allocated
    by new or not, or whether it's automatic or not.

    In you're case, I suggest you rethink your design, as this sounds
    pretty wacky to me. If you post some example code one could help you a
    bit more directly.

    Regards,

    Jens

    Comment

    • Greg

      #3
      Re: Problem on data location.

      shuisheng wrote:
      Dear All,
      >
      I am wondering if there is a way to know if a data is in heap? My case
      is like this:
      >
      I have a data and want to shallowly copy it into an object (just pass
      its head pointer). If the data is in heap, the object will take charge
      of deleting it.
      Making a shallow copy of a stack-allocated object does not strike me as
      a particularly good idea. Frankly, it's an accident waiting to happen.
      So it sounds as if there perhaps should be two types of copy methods
      offered by the class's interface - one shallow and one deep. In that
      case, it would be up to the client of the interface to choose the
      appropriate copy method.

      Alternately, the object's class interface can simply make it a
      precondition of the copy routine that the object to be copied must have
      been dynamically allocated. Such a precondition could even be enforced
      on a class-by-class basis by implementing a class whose instances
      cannot be allocated on the stack.

      Greg

      Comment

      Working...