From: Bob Hutchison Date: 2002-05-06T03:51:18+09:00 Subject: Re: Advice on Memory Related Performance Tuning On 5/5/02 10:32 AM, "Sean Russell" wrote: > Hi Bob, > > I can't answer most of your questions, but I can help you with the last: > > Bob Hutchison wrote: >> While playing around with this I thought of using an array to store the >> characters and then convert that to a string when necessary. >> >> Q3. How do you convert between an array of characters/fixnums and strings? > > Array.pack() and String.unpack(). > > If you're converting ISO-8859-1 text, use "C*" as the parameter to pack() > and unpack(). If you're doing UTF-8, use "U*". > > array = 'sean'.unpack('C*') > string = array.pack('C*') > > Check your favorite Ruby book for more options to pack() and unpack(). It > is a handy method, and fairly fast, although I'm not sure it would save you > much in the way of object allocation time. > > --- SER Thanks. This came up in another thread (I asked a couple of these questions more explicitly a few days after posting this message). The pack method is faster, but most importantly, it behaves better with bigger arrays (than the obvious method using << and a loop).