in reply to Are array based objects fixed length?

I have had some experience using arrays as objects. My objects were floating length and I have used two techniques to deal with issues like yours (although not to do with destruction). My experience is that the solution is determined by the way you use the arrays. For instance in one solution my arrays needed to suport push/pop. Thus the "common" elements were stored in fixed addresses starting at 0. In another solution for reasons I dont exactly remember I used negative indexes to reach common data.

My guess is that you should probably do

$obj->[0]=Pixie::Object::Info->new()
After all the first element is always in the same location (versus the last) and this still allows push/pop which is slightly more efficient than shift/unshift.

But I still say that without knowing the operations you need to perform on your objects (why pick arrays?) there is no way to give a really good answer.

update
I think you probably should just use a different route. _Demand_ that any client class must support a given method, lets say $obj->for_pixie(). This method MUST provide the functionality that when called with a value it stores it. When called at all it returns its current value. Something like

sub for_pixie { my $self=shift; $self->[0]=shift if @_; return $self->[0]; }
This way if the storage you need is transparent to you, and if the client class doesnt happen to be implemented as an array then all they have to do is change the method. You could even provide a set of "standard" base classes that already have this functionality (and a new() as well) for different implementations. eg Pixie::Client::Array Pixie::Client::Hash Pixie::Client::Filehandle etc...

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.

Replies are listed 'Best First'.
Re: Re: Are array based objects fixed length?
by pdcawley (Hermit) on Jul 26, 2002 at 10:59 UTC
    Um. No. An important design goal of Pixie was that you should be able to throw any object (for only slightly limited values of 'any') you like at pixie and the pixie would do its magic and store it. We already handle hash based objects quite handily, and array based objects that implement an _oid can be dealt with as 'top level' objects. If they don't implement _oid they can only be used in the contents of objects, subject to certain limitations.

    In general, the objects that are stored should never need to know that they've been persisted (they may want to know, but that shouldn't be a requirement). For instance, I have objects stored in Pixie, working quite happily, that have timestamps implemented using Time::Piece. Getting that to work too precisely no extra work on my part (apart from the work of implementing Pixie in the first place of course). Of course, there are CPAN modules that will need work to handle -- Set::Object, for instance, is a very handy class which can't be directly persisted by Pixie (which uses Data::Dumper to do a lot of its heavy lifting). However, we have a way forward, using $Data::Dumper::Freezer and Data::Dumper::Toaster, which should make even 'pathological' objects tractable to being stored (though maybe not to being 'top level' objects), and which we can use to provide hooks to users who need them.

    Hmm... maybe I should prepare a proper medition. Until then, you can take a look at the current (horribly undocumented) state of the Pixie art on CPAN.