From: Sam S. <sd...@gn...> - 2005-01-28 21:08:17
|
> * Bruno Haible <oe...@py...t> [2005-01-28 14:44:01 +0100]: > > Sam wrote: >> why is strm_bitbuffer a LISP heap-allocated object and not a malloc'ed >> memory area? > > Because it is stored in the stream, as a cache (for speed), and a pointer > to malloc'ed memory becomes invalid after savemem + loadmem. OOPS! flushing bitbuff on savemem?... converting bitbuff to a lisp vector on savemem and back on loadmem?... yuk... >> disadvantages: lack of modularity (tight coupling with the stream >> world) > Yes, this could be improved. please do. >> have to save the buffer when allocating bignum in bitbuff_is_I(). > This is normal when we work with Lisp objects. but in this specific case this is extremely inconvenient: it prevents bitbuff_to_I() from accepting a pointer to memory as the argument (see below ***). >> bitsize and bytesize; which is confusing (one should be enough) > > bytesize = ceiling(bitsize,8); > Indeed just two cheap arithmetic instructions. let's drop it, then. >> bitbuff_is_I()&bitbuff_ixu_sub can be rewritten as a general bits<->I API: > > Good idea. That could go into a new file, to be included from lisparit.d > right after intread.d: > intserial.d - serialization of integers as little-endian byte sequences ok. >> /* convert the bit buffer of the given length to a (un)signed integer */ >> maygc object bitbuff_to_I (const uintB* buffer, uintL length, bool signed_p); > > There probably need to be two variants of this function, one taking an > "const uintB* buffer", the other one taking an "object buffer" (a > simple-array of rank 1 and element-type (unsigned-byte 8)). > I would call these functions LEbytes_to_I and LEbytes_vector_to_I > instead of bitbuff_to_I. this need for two functions is the reason why the `maygc' property of bitbuff_to_I() is so bad (see above ***) > This intserial.d can be written indepedently of any streams. While > then changing stream.d to use it, please be careful with the quality > of the ASSERT_wr_int error message: a stream object with a filename in > it is very useful for the user when an error occurs. I hoped that you would take care of this. I'd rather not touch the bit-pushing code. -- Sam Steingold (http://www.podval.org/~sds) running w2k <http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/> <http://www.mideasttruth.com/> <http://www.honestreporting.com> I haven't lost my mind -- it's backed up on tape somewhere. |