Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: inside-out objects using arrays?

by fishbot_v2 (Chaplain)
on Sep 18, 2005 at 00:56 UTC ( #492950=note: print w/replies, xml ) Need Help??


in reply to Re^3: inside-out objects using arrays?
in thread inside-out objects using arrays?

You could avoid that problem by assigning the index to the first undef slot, rather than straight incrementing:

my $instance_index = List::Util::first { !defined $_ } @name;

You end up, though, with an O(n) constructor. But perhaps the savings in access make up for this.

Replies are listed 'Best First'.
Re^5: inside-out objects using arrays?
by chromatic (Archbishop) on Sep 18, 2005 at 02:20 UTC

    If you really want to save memory, you may want to avoid pinning your inside-out array at the high-water mark. Store a stack of reclaimed indices and push to it in the destructor and shift from it when generating the reference for a new object. Then you can shrink the array if necessary.

    (When you ask "Wait, won't it stay at the high-water mark even if there were 1000 elements and are only two now?", I'll sigh and talk about compacting garbage collectors and double-indirection the other flaws in this scheme. Still, it's a fun idea.)

      Hey, that's neat. I'll have to think about that. Thanks!
Re^5: inside-out objects using arrays?
by ikegami (Pope) on Sep 18, 2005 at 02:52 UTC
    Why not just convert @name to %name. You can keep using the numerical index. That changes the array into a sparse array. The time cost is quite minimal.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://492950]
help
Chatterbox?
[Corion]: Also, London is always a nice visit, as I got to meet a friend there, and spent some time offline, working on "minor" features of the shadertoy thing ;)
[marto]: maybe next year when the kids are a little older I'll have time to attend perl events in Europe
[Corion]: marto: Yeah - there isn't a Perl Day-Care at Perl events - we thought about it for YAPC::Europe 2012 but it's a gigantic effort to organize that
[marto]: Corion yeah, it'd be too costly for me to bring them both :P

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2016-12-07 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (125 votes). Check out past polls.