Index: ext/measure_memory.h
===================================================================
--- ext/measure_memory.h	(revision 0)
+++ ext/measure_memory.h	(revision 0)
@@ -0,0 +1,42 @@
+/* :nodoc: 
+ * Copyright (C) 2008  Alexander Dymo <adymo@pluron.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+
+#if defined(HAVE_RB_GC_ALLOCATED_SIZE)
+#define MEASURE_MEMORY 4
+ 
+static prof_measure_t
+measure_memory()
+{
+    return rb_gc_allocated_size();
+}
+
+static double
+convert_memory(prof_measure_t c)
+{ 
+    return  c / 1024; 
+}
+
+#endif
Index: ext/extconf.rb
===================================================================
--- ext/extconf.rb	(revision 228)
+++ ext/extconf.rb	(working copy)
@@ -16,5 +16,6 @@
 end
 
 have_header("sys/times.h")
-create_makefile("ruby_prof")
-have_func("rb_os_allocated_objects")
\ No newline at end of file
+have_func("rb_os_allocated_objects")
+have_func("rb_gc_allocated_size")
+create_makefile("ruby_prof")
\ No newline at end of file
Index: ext/ruby_prof.c
===================================================================
--- ext/ruby_prof.c	(revision 228)
+++ ext/ruby_prof.c	(working copy)
@@ -76,6 +76,7 @@
 #include "measure_wall_time.h"
 #include "measure_cpu_time.h"
 #include "measure_allocations.h"
+#include "measure_memory.h"
 
 static prof_measure_t (*get_measurement)() = measure_process_time;
 static double (*convert_measurement)(prof_measure_t) = convert_process_time;
@@ -1374,7 +1375,8 @@
    *RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock functions in the C Runtime library.
    *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
    *RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. 
-   *RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.*/
+   *RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.
+   *RubyProf::MEMORY - Measure memory size.  This requires a patched Ruby interpreter.*/
 static VALUE
 prof_get_measure_mode(VALUE self)
 {
@@ -1389,7 +1391,8 @@
    *RubyProf::PROCESS_TIME - Measure process time.  This is default.  It is implemented using the clock functions in the C Runtime library.
    *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
    *RubyProf::CPU_TIME - Measure time using the CPU clock counter.  This mode is only supported on Pentium or PowerPC platforms. 
-   *RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.*/
+   *RubyProf::ALLOCATIONS - Measure object allocations.  This requires a patched Ruby interpreter.
+   *RubyProf::MEMORY - Measure memory size.  This requires a patched Ruby interpreter.*/
 static VALUE
 prof_set_measure_mode(VALUE self, VALUE val)
 {
@@ -1427,6 +1430,13 @@
         break;
       #endif
         
+      #if defined(MEASURE_MEMORY)
+      case MEASURE_MEMORY:
+        get_measurement = measure_memory;
+        convert_measurement = convert_memory;
+        break;
+      #endif
+        
       default:
         rb_raise(rb_eArgError, "invalid mode: %d", mode);
         break;
@@ -1480,6 +1490,10 @@
           | RUBY_EVENT_LINE);
 #endif
 
+#if defined(MEASURE_MEMORY)
+    rb_gc_enable_stats();
+#endif
+
     return Qnil;
 }
 
@@ -1491,6 +1505,10 @@
 static VALUE
 prof_stop(VALUE self)
 {
+#if defined(MEASURE_MEMORY)
+    rb_gc_disable_stats();
+#endif
+
     VALUE result = Qnil;
 
     if (threads_tbl == NULL)
@@ -1563,6 +1581,10 @@
     rb_define_const(mProf, "ALLOCATIONS", INT2NUM(MEASURE_ALLOCATIONS));
     #endif
     
+    #if defined(MEASURE_MEMORY)
+    rb_define_const(mProf, "MEMORY", INT2NUM(MEASURE_MEMORY));
+    #endif
+    
     cResult = rb_define_class_under(mProf, "Result", rb_cObject);
     rb_undef_method(CLASS_OF(cMethodInfo), "new");
     rb_define_method(cResult, "threads", prof_result_threads, 0);
Index: Rakefile
===================================================================
--- Rakefile	(revision 228)
+++ Rakefile	(working copy)
@@ -1,4 +1,5 @@
 require 'rubygems'
+require 'date'
 require 'rake/gempackagetask'
 require 'rake/rdoctask'
 
@@ -84,7 +85,7 @@
 # Windows specification
 win_spec = default_spec.clone
 win_spec.extensions = []
-win_spec.platform = Gem::Platform::WIN32
+win_spec.platform = Gem::Platform::CURRENT
 win_spec.files += ["lib/#{SO_NAME}"]
 
 
Index: lib/ruby-prof/call_tree_printer.rb
===================================================================
--- lib/ruby-prof/call_tree_printer.rb	(revision 228)
+++ lib/ruby-prof/call_tree_printer.rb	(working copy)
@@ -18,12 +18,15 @@
         when RubyProf::WALL_TIME
           @value_scale = 1_000_000
           @output << 'wall_time'
-        when RubyProf::CPU_TIME
+        when RubyProf.const_defined?(:CPU_TIME) && RubyProf::CPU_TIME
           @value_scale = RubyProf.cpu_frequency
           @output << 'cpu_time'
-        when RubyProf::ALLOCATIONS
+        when RubyProf.const_defined?(:ALLOCATIONS) && RubyProf::ALLOCATIONS
           @value_scale = 1
           @output << 'allocations'
+        when RubyProf.const_defined?(:MEMORY) && RubyProf::MEMORY
+          @value_scale = 1
+          @output << 'memory'
       end
       @output << "\n\n"  
 
Index: lib/ruby-prof.rb
===================================================================
--- lib/ruby-prof.rb	(revision 228)
+++ lib/ruby-prof.rb	(working copy)
@@ -32,6 +32,8 @@
       RubyProf.measure_mode = RubyProf::CPU_TIME
     when "allocations"
       RubyProf.measure_mode = RubyProf::ALLOCATIONS
+    when "memory"
+      RubyProf.measure_mode = RubyProf::MEMORY
     else
       RubyProf.measure_mode = RubyProf::PROCESS_TIME
     end
