2 * object.c: Object creation for the Mono runtime
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
12 #include <mono/cli/cli.h>
13 #include <mono/cli/object.h>
16 * mono_object_allocate:
17 * @size: number of bytes to allocate
19 * This is a very simplistic routine until we have our GC-aware
22 * Returns: an allocated object of size @size, or NULL on failure.
25 mono_object_allocate (size_t size)
27 void *o = calloc (1, size);
35 * Frees the memory used by the object. Debugging purposes
36 * only, as we will have our GC system.
39 mono_object_free (MonoObject *o)
41 MonoClass *c = o->klass;
43 memset (o, 0, c->instance_size);
49 * @image: Context where the type_token is hosted
50 * @type_token: a token of the type that we want to create
52 * Returns: A newly created object whose definition is
53 * looked up using @type_token in the @image image
56 mono_object_new (MonoImage *image, guint32 type_token)
61 c = mono_class_get (image, type_token);
62 o = mono_object_allocate (c->instance_size);
70 * @image: image where the object is being referenced
71 * @etype: element type token
72 * @n: number of array elements
74 * This routine creates a new szarray with @n elements of type @token
77 mono_new_szarray (MonoImage *image, guint32 etype, guint32 n)
85 c = mono_array_class_get (image, etype, 1);
88 o = mono_object_allocate (c->instance_size);
91 ao = (MonoArrayObject *)o;
92 ac = (MonoArrayClass *)c;
94 ao->bounds = g_malloc0 (sizeof (MonoArrayBounds));
95 ao->bounds [0].length = n;
96 ao->bounds [0].lower_bound = 0;
98 ao->vector = g_malloc0 (n * ac->esize);