该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
<
index = freelist_index(sizeof(T));
if(index >= NODENUMS)
{
return NULL;
}
my_free_list = pHead->uFreelist + index;
//Lock(semid,LOCK_NUM);
result = *my_free_list;
if (result == 0)
{
ret = (pointer)refill((int)num, round_up(sizeof(T)));
}
else
{
*my_free_list = result->M_free_list_link;
ret = (pointer)result;
}
//UnLock(semid,LOCK_NUM);
pHead->iUseNum[index] = pHead->iUseNum[index] + (int)num;
if(0 == ret)
{
std::cerr <
exit(1);
}
std::cerr <
PrintFreelistAndCookie();
return ret;
}
void construct (pointer p, const T& value)
{
// initialize memory with placement new
new((void*)p)T(value);
}
void destroy (pointer p)
{
// destroy objects by calling their destructor
p->~T();
}
void deallocate (pointer p, size_type num)
{
Obj** my_free_list;
Obj* q ;
int index;
index = freelist_getindex(sizeof(T));
if(index >= NODENUMS)
{
std::cerr <
exit(1);
}
my_free_list = pHead->uFreelist + index;
q = (Obj*) p;
//Lock(semid,LOCK_NUM);
/*这个地方可能会有问题*/
//for(int i=0 ;i
{
q->M_free_list_link = *my_free_list;
*my_free_list = q;
}
//UnLock(semid,LOCK_NUM);
pHead->iUseNum[index] = pHead->iUseNum[index] - (int)num;
std::cerr <
<
<
PrintFreelistAndCookie();
}
};
template
int MyAlloc::round_up(int bytes)
{
int i;
i = bytes;
if(bytes
{
i = ALIGN;
}
std::cout<
return i;
};
template
int MyAlloc::freelist_index(int bytes)
{
int i;
for(i=0 ; i
{
if(pHead->sFreelistIndex[i] == bytes)
break;
}
if(i >= NODENUMS)
{
for(i=0 ; i
{
if(pHead->sFreelistIndex[i] == 0)
{
pHead->sFreelistIndex[i] = bytes;
std::cout<
return i;
}
}
}
std::cout<
return i;
};
template
int MyAlloc::freelist_getindex(int bytes)
{
int i;
for(i=0 ; i
{
if(pHead->sFreelistIndex[i] == bytes)
break;
}
std::cout<