Archived

This topic is now archived and is closed to further replies.

Austrian Coder

Convertig MMGR to c++

Recommended Posts

Hello! I am converting mmgr (HTTP://www.FluidStudios.com/publications.html) to c++. I am running in one problem.
// ---------------------------------------------------------------------------------------------------------------------------------
// Unused RAM calculation routines. Use these to determine how much of your RAM is unused (in bytes)
// ---------------------------------------------------------------------------------------------------------------------------------
unsigned int CMemoryTracker::CalcUnused(const sAllocUnit *allocUnit)
{
	const unsigned long	*ptr = reinterpret_cast(allocUnit->reportedAddress);
	unsigned int		count = 0;

	for (unsigned int i = 0; i < allocUnit->reportedSize; i += sizeof(long), ptr++)
	{
		if (*ptr == unusedPattern) count += sizeof(long);
	}

	return count;
}
 
Now i want to use it in this function:
	// ---------------------------------------------------------------------------------------------------------------------------------
	void dumpAllocations(FILE *fp)
	{
		fprintf(fp, "Alloc.   Addr       Size       Addr       Size                        BreakOn BreakOn              \r\n");
		fprintf(fp, "Number Reported   Reported    Actual     Actual     Unused    Method  Dealloc Realloc Allocated by \r\n");
		fprintf(fp, "------ ---------- ---------- ---------- ---------- ---------- -------- ------- ------- --------------------------------------------------- \r\n");
		
		
		for (unsigned int i = 0; i < hashSize; i++)
		{
			sAllocUnit *ptr = hashTable;
			while(ptr)
			{
				fprintf(fp, "%06d 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X %-8s    %c       %c    %s\r\n",
					ptr->allocationNumber,
					reinterpret_cast(ptr->reportedAddress), ptr->reportedSize,
					reinterpret_cast(ptr->actualAddress), ptr->actualSize,

////////////////////////
					CMemoryTracker::CalcUnused(ptr),
////////////////////////

					allocationTypes[ptr->allocationType],
					ptr->breakOnDealloc ? ''Y'':''N'',
					ptr->breakOnRealloc ? ''Y'':''N'',
					ownerString(ptr->sourceFile, ptr->sourceLine, ptr->sourceFunc));
				ptr = ptr->next;
			}
		}
	}
 
But here i get this error: C2352 ''CMemoryTracker::CalcUnused'' : illegal call of non-static member function How can i fix this? Thanks, Christian

Share this post


Link to post
Share on other sites
You can''t call member functions from the outside unless they are static(AFAIK).

Use some kind of singleton and call the function from there.

Share this post


Link to post
Share on other sites