MonoMemPool *next;
gint rest;
gpointer pos;
+ guint32 size;
union {
double pad; /* to assure proper alignment */
guint32 allocated;
pool->next = NULL;
pool->pos = (char *)pool + sizeof (MonoMemPool);
pool->rest = MONO_MEMPOOL_PAGESIZE - sizeof (MonoMemPool);
- pool->d.allocated = MONO_MEMPOOL_PAGESIZE;
+ pool->d.allocated = pool->size = MONO_MEMPOOL_PAGESIZE;
return pool;
}
/**
* mono_mempool_destroy:
- * @pool: the momory pool to destroy
+ * @pool: the memory pool to destroy
*
* Free all memory associated with this pool.
*/
}
}
+/**
+ * mono_mempool_invalidate:
+ * @pool: the memory pool to invalidate
+ *
+ * Fill the memory associated with this pool to 0x2a (42). Useful for debugging.
+ */
+void
+mono_mempool_invalidate (MonoMemPool *pool)
+{
+ MonoMemPool *p, *n;
+
+ p = pool;
+ while (p) {
+ n = p->next;
+ memset (p, 42, p->size);
+ p = n;
+ }
+}
+
void
mono_mempool_empty (MonoMemPool *pool)
{
MonoMemPool *np = g_malloc (sizeof (MonoMemPool) + size);
np->next = pool->next;
pool->next = np;
+ np->size = sizeof (MonoMemPool) + size;
pool->d.allocated += sizeof (MonoMemPool) + size;
return (char *)np + sizeof (MonoMemPool);
} else {
np->next = pool->next;
pool->next = np;
pool->pos = (char *)np + sizeof (MonoMemPool);
+ np->size = MONO_MEMPOOL_PAGESIZE;
pool->rest = MONO_MEMPOOL_PAGESIZE - sizeof (MonoMemPool);
pool->d.allocated += MONO_MEMPOOL_PAGESIZE;
}
return rval;
}
+/**
+ * mono_mempool_contains_addr:
+ *
+ * Determines whenever ADDR is inside the memory used by the mempool.
+ */
+gboolean
+mono_mempool_contains_addr (MonoMemPool *pool,
+ gpointer addr)
+{
+ MonoMemPool *p;
+
+ p = pool;
+ while (p) {
+ if (addr > (gpointer)p && addr <= (gpointer)((guint8*)p + p->size))
+ return TRUE;
+ p = p->next;
+ }
+
+ return FALSE;
+}