Owen Rudge orudge@codeweavers.com writes:
+struct memory_allocation +{
- struct list entry;
- void *ptr;
- struct list children;
+};
+static struct list memory_allocations = LIST_INIT(memory_allocations);
+static struct memory_allocation *find_allocation(struct list *searchList, void *parent) +{
- struct memory_allocation *allocation, *childAllocation;
- LIST_FOR_EACH_ENTRY(allocation, searchList, struct memory_allocation, entry)
- {
if (allocation->ptr == parent)
{
return allocation;
}
/* Search the children */
childAllocation = find_allocation(&allocation->children, parent);
if (childAllocation != NULL)
{
return childAllocation;
}
- }
- return NULL;
+}
You should probably store the child list at the start of the allocated block or something like that, you don't want to go through the entire list on every operation.