[#3006] CVS repository — "Eugene Scripnik" <hoaz@...>

Hello.

21 messages 2004/06/16
[#3008] Re: CVS repository — ts <decoux@...> 2004/06/16

>>>>> "E" == Eugene Scripnik <hoaz@gala.net> writes:

[#3009] Re: CVS repository — Michal Rokos <michal@...> 2004/06/16

Hi!

[#3057] Ruby 1.8.2 to be released. — matz@... (Yukihiro Matsumoto)

Hi,

20 messages 2004/06/23

spikes in memory usage

From: Jeff Mitchell <quixoticsycophant@...>
Date: 2004-06-09 23:42:48 UTC
List: ruby-core #2975
The following is an example of some memory problems I've been having
with my extension classes.  This is on AthlonXP 1.5GHz Linux with
gcc 3.3.2.

require './myclass'
size = ARGV.shift.to_i
loop {
   MyClass.new(size)
   1000.times {
      MyClass.new(size)
   }
}

size      mem usage
-------------------
1           1.6 meg
10          1.6 meg
100         2.1 meg
1000        7.8 meg
10000      61.0 meg
100000    277.0 meg
1000000    15.0 meg
10000000    2.7 meg
100000000   1.6 meg


extconf.rb
-----------
require 'mkmf'
create_makefile('myclass')


myclass.c
----------
#include "ruby.h"

struct MyStruct
{
    char* stuff ;
} ;

void myclass_free(struct MyStruct* data)
{
    free(data->stuff) ;
    free(data) ;
}

VALUE rb_myclass_initialize( VALUE self, VALUE size )
{
    struct MyStruct* data;
    Data_Get_Struct(self, struct MyStruct, data) ;
    data->stuff = (char*)malloc(NUM2LONG(size)*sizeof(char)) ;
    return self ;
}

static VALUE rb_myclass_s_allocate(VALUE klass)
{
    struct MyStruct* data ;
    VALUE obj = Data_Make_Struct(klass,
                                 struct MyStruct,
                                 0,
                                 myclass_free,
                                 data) ;
    return obj ;
}

VALUE cMyClass ;

void Init_myclass()
{
    cMyClass = rb_define_class("MyClass", rb_cObject) ;
    rb_define_alloc_func(cMyClass, rb_myclass_s_allocate) ;
    rb_define_method(cMyClass, "initialize", rb_myclass_initialize, 1) ;
}



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

In This Thread

Prev Next