summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--include/ruby/st.h1
-rw-r--r--st.c11
3 files changed, 17 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index bf8c371997..a2caf9df92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jun 17 06:48:28 2009 Koichi Sasada <ko1@atdot.net>
+
+ * st.c, include/ruby/st.h (st_memsize): added. This function returns
+ the memory usage of st_talbe.
+
Wed Jun 17 06:19:06 2009 Koichi Sasada <ko1@atdot.net>
* include/ruby/ruby.h: New structure RTypedData, added.
diff --git a/include/ruby/st.h b/include/ruby/st.h
index 0c80d3a225..aebdaf569d 100644
--- a/include/ruby/st.h
+++ b/include/ruby/st.h
@@ -107,6 +107,7 @@ int st_numcmp(st_data_t, st_data_t);
int st_numhash(st_data_t);
int st_strcasecmp(const char *s1, const char *s2);
int st_strncasecmp(const char *s1, const char *s2, size_t n);
+size_t st_memsize(st_table *);
#if defined(__cplusplus)
#if 0
diff --git a/st.c b/st.c
index 5fa7e24f53..01f2a43dc4 100644
--- a/st.c
+++ b/st.c
@@ -256,6 +256,17 @@ st_free_table(st_table *table)
free(table);
}
+size_t
+st_memsize(st_table *table)
+{
+ if (table->entries_packed) {
+ return table->num_bins * sizeof (void *) + sizeof(st_table);
+ }
+ else {
+ return table->num_entries * sizeof(struct st_table_entry) + table->num_bins * sizeof (void *) + sizeof(st_table);
+ }
+}
+
#define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))