Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: collections with values of fixed classes/lengths
Eric Mahurin
5/1/2005 9:43:00 PM
> > Anybody know of any collection (i.e. Array/Hash) classes
> where
> > the keys and/or values can be assigned a fixed class? And
> for
> > classes that have variable length objects the length be
> also
> > potentially fixed across the collection? The main purpose
> of
> > doing this would be memory usage. You wouldn't have to
> store
> > the class (and possibly object length and pointer to
> allocated
> > space) per element and instead just have the raw data in
> the
> > collection. You would be able to get the same memory
> > utilization as C per element if done right.
> >
> > Here would be a few examples of what I'm talking about and
> how
> > much space per element it would take:
> >
> > - array of Floats (64 bits per element)
> > - array of N-bit integers (N bits per element)
>
> For numerics there is for narray:
>
http://raa.ruby-lang.org/proj...
>
> > - hash of 2-character strings (2*8 bits per key and Object
> per
> > value)
> > - array of array of 8 Floats (8*64 bits per line)
>
> There's also pack and unpack which can be used to implement
> this.
>
> > For dealing with large data structures, this could be
> > invaluable for memory usage.
>
> "could" or "is"? Do you really know that you need this or is
> this just
> guessing?
Thanks Robert and Christian. I think NArray will work for many
uses.
I still think a more general extension would be nice. And
Robert, I guess you might say I'm guessing. I'm new to ruby,
but from my perl usage, I know of many times I've dealt with
large amounts of data and would have wanted more C-like
efficiency.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail...
1 Answer
Robert Klemme
5/2/2005 6:29:00 AM
0
"Eric Mahurin" <eric_mahurin@yahoo.com> schrieb im Newsbeitrag
news:20050501214236.96659.qmail@web41121.mail.yahoo.com...
>> > Anybody know of any collection (i.e. Array/Hash) classes
>> where
>> > the keys and/or values can be assigned a fixed class? And
>> for
>> > classes that have variable length objects the length be
>> also
>> > potentially fixed across the collection? The main purpose
>> of
>> > doing this would be memory usage. You wouldn't have to
>> store
>> > the class (and possibly object length and pointer to
>> allocated
>> > space) per element and instead just have the raw data in
>> the
>> > collection. You would be able to get the same memory
>> > utilization as C per element if done right.
>> >
>> > Here would be a few examples of what I'm talking about and
>> how
>> > much space per element it would take:
>> >
>> > - array of Floats (64 bits per element)
>> > - array of N-bit integers (N bits per element)
>>
>> For numerics there is for narray:
>>
http://raa.ruby-lang.org/proj...
>>
>> > - hash of 2-character strings (2*8 bits per key and Object
>> per
>> > value)
>> > - array of array of 8 Floats (8*64 bits per line)
>>
>> There's also pack and unpack which can be used to implement
>> this.
>>
>> > For dealing with large data structures, this could be
>> > invaluable for memory usage.
>>
>> "could" or "is"? Do you really know that you need this or is
>> this just
>> guessing?
>
>
> Thanks Robert and Christian. I think NArray will work for many
> uses.
You're welcome.
> I still think a more general extension would be nice. And
> Robert, I guess you might say I'm guessing. I'm new to ruby,
> but from my perl usage, I know of many times I've dealt with
> large amounts of data and would have wanted more C-like
> efficiency.
;-)
As Mark has demonstrated, you can stuff anything into a String with pack and
unpack.
Btw, Mark, if you factor out conversion to string and from string (hint
traits), you have a generic implementation for any fixed size type. Maybe
this should go somewhere into the std lib...
Kind regards
robert
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: collections with values of fixed classes/lengths
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password