+2005-01-08 Ben Maurer <bmaurer@ximian.com>
+
+ * object.c (mono_object_get_size): New function to get the size of
+ an object instance.
+
+ * profiler.c (simple_allocation): Use above.
+
2005-01-08 Sebastien Pouliot <sebastien@ximian.com>
* appdomain.c: Replaced ves_icall_System_AppDomain_getDomainByID by
size = obj->vtable->klass->instance_size;
o = mono_object_allocate (size);
- mono_profiler_allocation (o, obj->vtable->klass);
-
memcpy (o, obj, size);
+
+ mono_profiler_allocation (o, obj->vtable->klass);
if (obj->vtable->klass->has_finalize)
mono_object_register_finalizer (o);
{
return mono_object_class (obj);
}
+/**
+ * mono_object_get_size:
+ * @o: object to query
+ *
+ * Returns: the size, in bytes, of @o
+ */
+guint
+mono_object_get_size (MonoObject* o)
+{
+ MonoClass* klass = mono_object_class (o);
+
+ if (klass == mono_defaults.string_class)
+ return sizeof (MonoString) + 2 * mono_string_length ((MonoString*) o) + 2;
+ else if (klass->parent == mono_defaults.array_class)
+ return sizeof (MonoArray) + mono_array_element_size (klass) * mono_array_length ((MonoArray*) o);
+ else
+ return mono_class_instance_size (klass);
+}
/**
* mono_object_unbox:
profile_info->alloc_info = tmp;
}
tmp->count++;
- if (klass == mono_defaults.string_class) {
- tmp->mem += sizeof (MonoString) + 2 * mono_string_length ((MonoString*)obj) + 2;
- } else if (klass->parent == mono_defaults.array_class) {
- tmp->mem += sizeof (MonoArray) + mono_array_element_size (klass) * mono_array_length ((MonoArray*)obj);
- } else {
- tmp->mem += mono_class_instance_size (klass);
- }
+ tmp->mem += mono_object_get_size (obj);
}
static void