> The data which needs to be stored along with the buffer data, can be
> stored as either a header or a footer. The size of this header needs to be
> a multiple of 16 (or possibly even 8) bytes, so that the real buffer
> which follows would be correctly aligned. I'm not sure if this applies for
> a footer.

> A footer might allow us to to tack 5-8 bytes on to the end of an
> allocation, which might not always go 'over' the 16 byte rounding-up limit
> we currently have in place. As long as we're not just-below the 16 byte
> barrier on most of our allocations, this shouldn't waste any more memory.

My current code (see
http://www.mail-archive.com/perl6-internals@perl.org/msg09196.html) requires
one flag byte within the buffer itself, provided the buffer is always
guaranteed to be large enough to hold a pointer, which the current 16-byte
allocation scheme ensures. To implement substrings requires an additional
pointer (or offset) in the string header.
I was assuming that we only want to implement COW for strings, as non-string
buffers are generally speaking not under our control.

I still think that the cheapest implementation for the flag byte is a
footer, as we don't need to worry about alignment. This is actually a
zero-cost option as far as memory allocation is concerned, as the current
allocation scheme always allocates at least one extra byte.

Variable-sized string headers are not really an option; if the overhead of
an additional pointer is a problem, my first inclination would be to combine
the chartype and encoding pointers into a single vtable entry.

Dan's recent addition of (re)allocate_about conflicts with my current footer
implementation, so I do not have a synced-up version of my COW code at
present. These functions have also re-introduced the string growth problem
(see http://www.mail-archive.com/perl6-internals@perl.org/msg09322.html);
the patch and sample program below can be used to illustrate this.

--
Peter Gibbs
EmKel Systems


Index: core.ops
===================================================================
RCS file: /home/perlcvs/parrot/core.ops,v
retrieving revision 1.130
diff -u -r1.130 core.ops
--- core.ops  24 Apr 2002 20:31:39 -0000  1.130
+++ core.ops  28 Apr 2002 10:59:35 -0000
@@ -2366,6 +2366,18 @@

 =cut

+=item B<debug>(in STR)
+
+Print string header information for debugging purposes.
+
+=cut
+
+inline op debug(in STR) {
+  printf("%p -> %p; buflen %lu, bufused %lu, flags %lx\n",
+         $1, $1->bufstart, $1->buflen, $1->bufused, $1->flags);
+  goto NEXT();
+}
+


############################################################################
###


 set S0, "test"
 set S1, S0
 debug S1
 clone S2, S1
 clone S1, S2
 clone S2, S1
 clone S1, S2
 clone S2, S1
 clone S1, S2
 debug S1
 end


Reply via email to