* 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.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2009-06-16 22:36:27 +00:00
Родитель 51d174a177
Коммит 3caa4ee5e5
7 изменённых файлов: 113 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,17 @@
Wed Jun 17 07:24:26 2009 Koichi Sasada <ko1@atdot.net>
* 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@atdot.net>
* iseq.c (iseq_memsize): added. Use RTypedData instead of RData

11
array.c
Просмотреть файл

@ -386,6 +386,17 @@ rb_ary_free(VALUE ary)
}
}
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)
{

14
io.c
Просмотреть файл

@ -3317,6 +3317,20 @@ rb_io_fptr_finalize(rb_io_t *fptr)
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)
{

Просмотреть файл

@ -5202,6 +5202,20 @@ onig_free(regex_t* reg)
}
}
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);\

Просмотреть файл

@ -758,6 +758,17 @@ rb_str_free(VALUE str)
}
}
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)
{

Просмотреть файл

@ -798,6 +798,24 @@ rb_transcoding_close(rb_transcoding *tc)
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 @@ rb_econv_close(rb_econv_t *ec)
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)
{

Просмотреть файл

@ -919,6 +919,15 @@ rb_free_generic_ivar(VALUE obj)
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)
{