Example #1
0
void	operator delete( void* iPtr ) {
	if ( iPtr == NULL )
		return;

	// 引数のメモリがテーブル内に存在するか?
	int	i = TableSearch( PointerHash(iPtr), iPtr );
	if ( i == -1 )
		throw Exception("確保された記録のないメモリを解放しようとしました。");
	// 解放処理
	free( gTable[i] );
	gTable[i] = NULL;
	gBlockSize[i] = 0;
}
Example #2
0
File: table.c Project: gdkar/picoc
/* find a value in a table. returns FALSE if not found. 
 * Key must be a shared string from TableStrRegister() */
int TableGet(struct Table *Tbl, const char *Key, struct Value **Val, const char **DeclFileName, int *DeclLine, int *DeclColumn)
{
    int AddAt;
    struct TableEntry *FoundEntry = TableSearch(Tbl, Key, &AddAt);
    if (!FoundEntry ) return FALSE;
    *Val = FoundEntry->p.v.Val;
    if (DeclFileName){
        *DeclFileName = FoundEntry->DeclFileName;
        *DeclLine = FoundEntry->DeclLine;
        *DeclColumn = FoundEntry->DeclColumn;
    }
    return TRUE;
}
Example #3
0
File: table.c Project: gdkar/picoc
/* set an identifier to a value. returns FALSE if it already exists. 
 * Key must be a shared string from TableStrRegister() */
int TableSet(Picoc *pc, struct Table *Tbl, char *Key, struct Value *Val, const char *DeclFileName, int DeclLine, int DeclColumn){
    int AddAt;
    struct TableEntry *FoundEntry = TableSearch(Tbl, Key, &AddAt);
    if (FoundEntry == NULL)
    {   /* add it to the table */
        struct TableEntry *NewEntry = VariableAlloc(pc, NULL, sizeof(struct TableEntry), Tbl->OnHeap);
        NewEntry->DeclFileName = DeclFileName;
        NewEntry->DeclLine = DeclLine;
        NewEntry->DeclColumn = DeclColumn;
        NewEntry->p.v.Key = Key;
        NewEntry->p.v.Val = Val;
        NewEntry->Next = Tbl->HashTable[AddAt];
        Tbl->HashTable[AddAt] = NewEntry;
        return TRUE;
    }
    return FALSE;
}
Example #4
0
void*	operator new( size_t iSize ) {
	static	int	theAllocCount=0;

	void*	thePtr = malloc( iSize );
	memset( thePtr, 0xac, iSize );	// 確保したメモリを埋めておく
	if ( thePtr == NULL )
		throw Exception("メモリが足りません。");

	// 格納位置を得る
	int	i = TableSearch( PointerHash(thePtr), NULL );
	if ( i == -1 )
		throw Exception("メモリブロック格納テーブルが一杯です。");
	// 確保したメモリのアドレスを保持しておく
	gTable[i] = thePtr;
	gBlockSize[i] = iSize;
	gAllocCount[i] = theAllocCount++;
	return	thePtr;
}