nsIContent ** flatArray = (nsIContent **)malloc(numElements * sizeof(void *));
nsIContent ** flatArray = new nsIContent*[numElements];
XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, PRInt32 indentLevel){	PRInt32			childIndex = 0, numChildren = 0, nameSpaceID;        nsCOMPtr<nsIContent>	child;	nsresult		rv;	nsVoidArray		*childArray;	if (NS_FAILED(rv = container->ChildCount(numChildren)))	return(rv);        if ((childArray = new nsVoidArray()) == nsnull)	return (NS_ERROR_OUT_OF_MEMORY);	for (childIndex=0; childIndex<numChildren; childIndex++)	{		if (NS_FAILED(rv = container->ChildAt(childIndex, *getter_AddRefs(child))))	break;		if (NS_FAILED(rv = child->GetNameSpaceID(nameSpaceID)))	break;		if (nameSpaceID == kNameSpaceID_XUL)		{			nsCOMPtr<nsIAtom> tag;			if (NS_FAILED(rv = child->GetTag(*getter_AddRefs(tag))))	return rv;			if (tag.get() == kTreeItemAtom)			{			        nsIContent	*cell;				if (NS_SUCCEEDED(rv = GetTreeCell(child, colIndex, &cell)))				{					if (cell)					{						nsString	val;						if (NS_SUCCEEDED(rv = GetTreeCellValue(cell, val)))						{							// hack:  always append cell value 1st as							//        that's what sort callback expects							childArray->AppendElement(val.ToNewCString());							childArray->AppendElement(child);						}					}				}			}		}	}	unsigned long numElements = childArray->Count();	if (numElements > 1)	{		nsIContent ** flatArray = (nsIContent **)malloc(numElements * sizeof(void *));		if (flatArray)		{			_sortStruct		sortInfo;			sortInfo.descendingSort = PR_TRUE;			// flatten array of resources, sort them, then add as tree elements			unsigned long loop;		        for (loop=0; loop<numElements; loop++)				flatArray[loop] = (nsIContent *)childArray->ElementAt(loop);			rdf_qsort((void *)flatArray, numElements/2, 2 * sizeof(void *),				inplaceSortCallback, (void *)&sortInfo);			RemoveAllChildren(container);			if (NS_FAILED(rv = container->UnsetAttribute(kNameSpaceID_None,			                        kTreeContentsGeneratedAtom,			                        PR_FALSE)))			{				printf("unable to clear contents-generated attribute\n");			}						// insert sorted children						numChildren = 0;			for (loop=0; loop<numElements; loop+=2)			{				container->InsertChildAt((nsIContent *)flatArray[loop+1], numChildren++, PR_TRUE);			}		}	}	delete(childArray);	return(rv);}