void
JMMHashTable::_AddNewRecord
(
    const JMMRecord& record,
    const JBoolean   checkDoubleAllocation
)
{
    JHashCursor<JMMRecord> cursor(itsAllocatedTable, reinterpret_cast<JHashValue>( record.GetAddress() ) );
    if (checkDoubleAllocation)
    {
        cursor.ForceNextMapInsertHash();
        if ( cursor.IsFull() )
        {
            JMMRecord thisRecord = cursor.GetValue();
            itsAllocatedBytes   -= thisRecord.GetSize();
            NotifyMultipleAllocation(record, thisRecord);
        }
        // Might as well trust malloc--the table should never have duplicate
        // entries!
    }
    else
    {
        cursor.ForceNextOpen();
    }
    cursor.Set(reinterpret_cast<JHashValue>( record.GetAddress() ), record);
    itsAllocatedBytes += record.GetSize();
}
void
JMMArrayTable::_AddNewRecord
	(
	const JMMRecord& record,
	const JBoolean   checkDoubleAllocation
	)
{
	JSize index = 0;

	if (checkDoubleAllocation)
		{
		index = FindAllocatedBlock( record.GetAddress() );
		}

	if (index == 0)
		{
		// Append because new allocations tend to be free'd the fastest
		itsAllocatedTable->AppendElement(record);
		}
	else
		{
		JMMRecord thisRecord = itsAllocatedTable->GetElement(index);
		itsAllocatedBytes   -= thisRecord.GetSize();

		NotifyMultipleAllocation(record, thisRecord);

		// Might as well trust malloc--the table should never have duplicate
		// entries!
		itsAllocatedTable->SetElement(index, record);
		}

	itsAllocatedBytes += record.GetSize();
}
JSize
JMMArrayTable::FindAllocatedBlock
	(
	const void* block
	)
	const
{
	JSize allocatedCount = itsAllocatedTable->GetElementCount();
	for (JSize i=allocatedCount;i>=1;i--)
		{
		const JMMRecord thisRecord = itsAllocatedTable->GetElement(i);
		if (thisRecord.GetAddress() == block)
			{
			return i;
			}
		}

	return 0;
}
void
JMemoryManager::DeleteRecord
	(
	void*             block,
	const JCharacter* file,
	const JUInt32     line,
	const JBoolean    isArray
	)
{
	if (block == NULL)
		{
		HandleNULLDeleted(file, line, isArray);
		}
	else
		{
		JBoolean wasAllocated;
		if (itsMemoryTable != NULL)
			{
			JMMRecord record;
			wasAllocated = itsMemoryTable->SetRecordDeleted(&record, block,
															file, line, isArray);
			// Can't do this unless we're keeping records
			if (itsShredFlag && wasAllocated)
				{
				assert(record.GetAddress() == block);
				memset(block, itsDeallocateGarbage, record.GetSize() );
				}
			}
		else
			{
			wasAllocated = kJTrue; // Have to trust the client
			}

		// Try to avoid a seg fault so the program can continue
		if (wasAllocated)
			{
			free(block);
			}
		}
}
JSize
JMMArrayTable::FindDeletedBlock
	(
	const void* block
	)
	const
{
	if (itsDeletedTable != NULL)
		{
		JSize deletedCount = itsDeletedTable->GetElementCount();
		for (JSize i=deletedCount;i>=1;i--)
			{
			const JMMRecord thisRecord = itsDeletedTable->GetElement(i);
			if (thisRecord.GetAddress() == block)
				{
				return i;
				}
			}
		}

	return 0;
}