ruby-changes:12047
From: ko1 <ko1@a...>
Date: Wed, 17 Jun 2009 07:36:48 +0900 (JST)
Subject: [ruby-changes:12047] Ruby:r23714 (trunk): * array.c (rb_ary_memsize): added.
ko1 2009-06-17 07:36:27 +0900 (Wed, 17 Jun 2009) New Revision: 23714 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23714 Log: * array.c (rb_ary_memsize): added. * io.c (rb_io_memsize): added. * regcomp.c (onig_memsize): added. * string.c (rb_str_memsize): added. * transcode.c (rb_transcoding_memsize, rb_econv_memsize): added. * variable.c (rb_geneic_ivar_memsize): added. Modified files: trunk/ChangeLog trunk/array.c trunk/io.c trunk/regcomp.c trunk/string.c trunk/transcode.c trunk/variable.c Index: array.c =================================================================== --- array.c (revision 23713) +++ array.c (revision 23714) @@ -386,6 +386,17 @@ } } +size_t +rb_ary_memsize(VALUE ary) +{ + if (ARY_OWNS_HEAP_P(ary)) { + return RARRAY(ary)->as.heap.aux.capa * sizeof(VALUE); + } + else { + return 0; + } +} + static inline void ary_discard(VALUE ary) { Index: regcomp.c =================================================================== --- regcomp.c (revision 23713) +++ regcomp.c (revision 23714) @@ -5202,6 +5202,20 @@ } } +size_t +onig_memsize(regex_t *reg) +{ + size_t size = sizeof(regex_t); + if (IS_NOT_NULL(reg->p)) size += reg->alloc; + if (IS_NOT_NULL(reg->exact)) size += reg->exact_end - reg->exact; + if (IS_NOT_NULL(reg->int_map)) size += sizeof(int) * ONIG_CHAR_TABLE_SIZE; + if (IS_NOT_NULL(reg->int_map_backward)) size += sizeof(int) * ONIG_CHAR_TABLE_SIZE; + if (IS_NOT_NULL(reg->repeat_range)) size += reg->repeat_range_alloc * sizeof(OnigRepeatRange); + if (IS_NOT_NULL(reg->chain)) size += onig_memsize(reg->chain); + + return size; +} + #define REGEX_TRANSFER(to,from) do {\ (to)->state = ONIG_STATE_MODIFY;\ onig_free_body(to);\ Index: ChangeLog =================================================================== --- ChangeLog (revision 23713) +++ ChangeLog (revision 23714) @@ -1,3 +1,17 @@ +Wed Jun 17 07:24:26 2009 Koichi Sasada <ko1@a...> + + * array.c (rb_ary_memsize): added. + + * io.c (rb_io_memsize): added. + + * regcomp.c (onig_memsize): added. + + * string.c (rb_str_memsize): added. + + * transcode.c (rb_transcoding_memsize, rb_econv_memsize): added. + + * variable.c (rb_geneic_ivar_memsize): added. + Wed Jun 17 07:04:33 2009 Koichi Sasada <ko1@a...> * iseq.c (iseq_memsize): added. Use RTypedData instead of RData Index: variable.c =================================================================== --- variable.c (revision 23713) +++ variable.c (revision 23714) @@ -919,6 +919,15 @@ st_free_table((st_table *)tbl); } +size_t +rb_geneic_ivar_memsize(VALUE obj) +{ + st_data_t tbl; + if (st_delete(generic_iv_tbl, &obj, &tbl)) + return st_memsize((st_table *)tbl); + return 0; +} + void rb_copy_generic_ivar(VALUE clone, VALUE obj) { Index: string.c =================================================================== --- string.c (revision 23713) +++ string.c (revision 23714) @@ -758,6 +758,17 @@ } } +size_t +rb_str_memsize(VALUE str) +{ + if (!STR_EMBED_P(str) && !STR_SHARED_P(str)) { + return RSTRING(str)->as.heap.aux.capa; + } + else { + return 0; + } +} + VALUE rb_str_to_str(VALUE str) { Index: io.c =================================================================== --- io.c (revision 23713) +++ io.c (revision 23714) @@ -3317,6 +3317,20 @@ return 1; } +size_t rb_econv_memsize(rb_econv_t *); + +size_t +rb_io_memsize(rb_io_t *fptr) +{ + size_t size = sizeof(rb_io_t); + size += fptr->rbuf_capa; + size += fptr->wbuf_capa; + size += fptr->cbuf_capa; + if (fptr->readconv) size += rb_econv_memsize(fptr->readconv); + if (fptr->writeconv) size += rb_econv_memsize(fptr->writeconv); + return size; +} + VALUE rb_io_close(VALUE io) { Index: transcode.c =================================================================== --- transcode.c (revision 23713) +++ transcode.c (revision 23714) @@ -798,6 +798,24 @@ xfree(tc); } +static size_t +rb_transcoding_memsize(rb_transcoding *tc) +{ + size_t size = sizeof(rb_transcoding); + const rb_transcoder *tr = tc->transcoder; + + if (TRANSCODING_STATE_EMBED_MAX < tr->state_size) { + size += tr->state_size; + } + if (sizeof(tc->readbuf.ary) < tr->max_input) { + size += tr->max_input; + } + if (sizeof(tc->writebuf.ary) < tr->max_output) { + size += tr->max_output; + } + return size; +} + static rb_econv_t * rb_econv_alloc(int n_hint) { @@ -1663,6 +1681,28 @@ xfree(ec); } +size_t +rb_econv_memsize(rb_econv_t *ec) +{ + size_t size = sizeof(rb_econv_t); + int i; + + if (ec->replacement_allocated) { + size += ec->replacement_len; + } + for (i = 0; i < ec->num_trans; i++) { + size += rb_transcoding_memsize(ec->elems[i].tc); + + if (ec->elems[i].out_buf_start) { + size += ec->elems[i].out_buf_end - ec->elems[i].out_buf_start; + } + } + size += ec->in_buf_end - ec->in_buf_start; + size += sizeof(rb_econv_elem_t) * ec->num_allocated; + + return size; +} + int rb_econv_putbackable(rb_econv_t *ec) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/