Nicholas Clark <[EMAIL PROTECTED]> wrote: > On Wed, Mar 30, 2005 at 09:11:51AM +0200, Leopold Toetsch wrote: >> Bernhard Schmalhofer <[EMAIL PROTECTED]> wrote: >> > + void freeze(visit_info *info) { >> > + IMAGE_IO *io = info->image_io; >> > + io->vtable->push_integer(INTERP, io, PMC_int_val(SELF)); >> > + STRING * s = string_from_cstring(INTERP, PMC_data(SELF), >> > PMC_int_val2(SELF)/BITS_PER_CHAR); >> > + io->vtable->push_string(INTERP, io, s); >> > + } >> >> Hehe. Clever trick.
> Could one of you explain how this works? I've tried to work it out and it's > not obvious to me. The C<freeze> vtable appends an INTVAL (the array size) and the the bit image of the bit array as a STRING to the frozen image. PMC_int_val2 is the rounded up value of bits allocated. The C<string_from_cstring> creates just a string header, with the string memory pointing to the bit image. NB, if the array was shrinked, the rounded up value of the array size would be more efficient. > Nicholas Clark leo