POV-Ray : Newsgroups : povray.off-topic : Binary trees, branches and leaves : Re: Binary trees, branches and leaves Server Time
4 Sep 2024 15:19:17 EDT (-0400)
  Re: Binary trees, branches and leaves  
From: Warp
Date: 5 Mar 2010 08:51:45
Message: <4b910c6f@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> Wouldn't you just need to determine the storage requirements of THE 
> LARGEST class of object? And allocate that amount for every object?

  No, because indexing is done based on the type of the array. For the
indexing to work properly the array type would have to be that of the
largest object type, but then you wouldn't be able to easily store any
other type of objects there (because now you would be handling objects
of the most derived class type rather than objects of the base class
type).

  You could probably get around this limitation by creating an array
container class which handles the memory allocation and indexing using
low-level functionalities (raw pointer arithmetic and such), but it would
be quite a hack. And you wouldn't be able to use pointer arithmetic on
the array directly (except by using more abstract iterators).

  Then there's the problem of assigning objects: If you assign an object
to a place in the array where there's already an object, and they are of
different types... I don't think it would work. Maybe you could get around
it by first destroying the existing object and then placing the new object
in its place using placement new, but it becomes complicated.

  Perhaps not *impossible*, but as you may guess, quite hard and kludgey.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.