Next: sweep_strings, Previous: sweep_lcrecords_1, Up: Garbage Collection - Step by Step [Contents][Index]
compact_string_chars
The purpose of this function is to compact all the data parts of the
strings that are held in so-called string_chars_block
, i.e. the
strings that do not exceed a certain maximal length.
The procedure with which this is done is as follows. We are keeping two
positions in the string_chars_block
s using two pointer/integer
pairs, namely from_sb
/from_pos
and
to_sb
/to_pos
. They stand for the actual positions, from
where to where, to copy the actually handled string.
While going over all chained string_char_block
s and their held
strings, staring at first_string_chars_block
, both pointers
are advanced and eventually a string is copied from from_sb
to
to_sb
, depending on the status of the pointed at strings.
More precisely, we can distinguish between the following actions.
from_sb
’s position could be marked as free, which
is indicated by an invalid pointer to the pointer that should point back
to the fixed size string object, and which is checked by
FREE_STRUCT_P
. In this case, the from_sb
/from_pos
is advanced to the next string, and nothing has to be copied.
from_sb
/from_pos
pair as described above.
to_sb
-block, we advance
this pointer to the beginning of the next block before copying. In case the
from and to positions are different, we perform the
actual copying using the library function memmove
.
After compacting, the pointer to the current
string_chars_block
, sitting in current_string_chars_block
,
is reset on the last block to which we moved a string,
i.e. to_block
, and all remaining blocks (we know that they just
carry garbage) are explicitly xfree
d.
Next: sweep_strings, Previous: sweep_lcrecords_1, Up: Garbage Collection - Step by Step [Contents][Index]