From: Eric Mahurin Date: 2005-05-03T04:57:59+09:00 Subject: Re: collections with values of fixed classes/lengths > > > > 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... > > > > That would be great. What do you mean by "fixed size > type"? > > Does that mean you couldn't use this class to make a > > homogeneous array of strings, arrays, or hashes? The way I > was > > thinking you'd handle the complex object case would be to > give > > "new" an initial object instead of a simply a class. From > > this, you could tell how much flattening to do in the > array. > > I can see some benefit in an array (or even hash) of > fixed-size data > items; sometimes memory usage considerations are more > important than > flexibility. The fact that the homogeneity is enforced I saw > as a > somewhat unfortunate side-effect, though maybe I'm just too > used to > Ruby's very dynamic nature. Why would you want to > artificially force > the contents of an array to be all the same type? Why > preclude any > possibility of duck typing? I just have the feeling that > anyone using > this would have it bite them later on, when they want to use > the full > flexibility of Ruby, and can't. I think you answered your own question - "sometimes memory usage considerations are more important than flexibility". To get this memory efficiency you would only be able to store objects of one class because you would be storing only the data per element - no class information. You wouldn't even be able to put nil objects in for a homogeneous array - you may have to pick some value to mean nil if you need that. Where you can take advantage of this, I was hoping you could just replace "Array" with "HomogeneousArray". You could always back out to Array if this becomes to inflexible. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com