Twiddling with allocation for 64-bit architectures

git-svn-id: http://picoc.googlecode.com/svn/trunk@378 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-11-06 18:08:11 +00:00
parent 5c86cfaf36
commit 3162c1a2bf
3 changed files with 21 additions and 12 deletions

View file

@ -546,7 +546,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
debugf("ExpressionInfixOperator()\n");
if (BottomValue == NULL || TopValue == NULL)
ProgramFail(Parser, "bad expression");
ProgramFail(Parser, "invalid expression");
if (Op == TokenLeftSquareBracket)
{

29
heap.c
View file

@ -126,7 +126,7 @@ void *HeapAllocMem(int Size)
#else
struct AllocNode *NewMem = NULL;
struct AllocNode **FreeNode;
int AllocSize = MEM_ALIGN(Size) + sizeof(NewMem->Size);
int AllocSize = MEM_ALIGN(Size) + MEM_ALIGN(sizeof(NewMem->Size));
int Bucket;
if (Size == 0)
@ -140,7 +140,8 @@ void *HeapAllocMem(int Size)
Bucket = AllocSize >> 2;
if (Bucket < FREELIST_BUCKETS && FreeListBucket[Bucket] != NULL)
{ /* try to allocate from a freelist bucket first */
{
/* try to allocate from a freelist bucket first */
#ifdef DEBUG_HEAP
printf("allocating %d(%d) from bucket", Size, AllocSize);
#endif
@ -151,7 +152,8 @@ void *HeapAllocMem(int Size)
NewMem->Size = AllocSize;
}
else if (FreeListBig != NULL)
{ /* grab the first item from the "big" freelist we can fit in */
{
/* grab the first item from the "big" freelist we can fit in */
for (FreeNode = &FreeListBig; *FreeNode != NULL && (*FreeNode)->Size < AllocSize; FreeNode = &(*FreeNode)->NextFree)
{}
@ -159,8 +161,9 @@ void *HeapAllocMem(int Size)
{
assert((unsigned long)*FreeNode >= (unsigned long)&HeapMemory[0] && (unsigned char *)*FreeNode - &HeapMemory[0] < HEAP_SIZE);
assert((*FreeNode)->Size < HEAP_SIZE && (*FreeNode)->Size > 0);
if ((*FreeNode)->Size < Size + SPLIT_MEM_THRESHOLD)
{ /* close in size - reduce fragmentation by not splitting */
if ((*FreeNode)->Size < AllocSize + SPLIT_MEM_THRESHOLD)
{
/* close in size - reduce fragmentation by not splitting */
#ifdef DEBUG_HEAP
printf("allocating %d(%d) from freelist, no split (%d)", Size, AllocSize, (*FreeNode)->Size);
#endif
@ -169,7 +172,8 @@ void *HeapAllocMem(int Size)
*FreeNode = NewMem->NextFree;
}
else
{ /* split this big memory chunk */
{
/* split this big memory chunk */
#ifdef DEBUG_HEAP
printf("allocating %d(%d) from freelist, split chunk (%d)", Size, AllocSize, (*FreeNode)->Size);
#endif
@ -182,7 +186,8 @@ void *HeapAllocMem(int Size)
}
if (NewMem == NULL)
{ /* couldn't allocate from a freelist - try to increase the size of the heap area */
{
/* couldn't allocate from a freelist - try to increase the size of the heap area */
#ifdef DEBUG_HEAP
printf("allocating %d(%d) at bottom of heap (0x%lx-0x%lx)", Size, AllocSize, (long)(HeapBottom - AllocSize), (long)HeapBottom);
#endif
@ -217,7 +222,8 @@ void HeapFreeMem(void *Mem)
return;
if ((void *)MemNode == HeapBottom)
{ /* pop it off the bottom of the heap, reducing the heap size */
{
/* pop it off the bottom of the heap, reducing the heap size */
#ifdef DEBUG_HEAP
printf("freeing %d from bottom of heap\n", MemNode->Size);
#endif
@ -227,7 +233,8 @@ void HeapFreeMem(void *Mem)
#endif
}
else if (Bucket < FREELIST_BUCKETS)
{ /* we can fit it in a bucket */
{
/* we can fit it in a bucket */
#ifdef DEBUG_HEAP
printf("freeing %d to bucket\n", MemNode->Size);
#endif
@ -236,7 +243,8 @@ void HeapFreeMem(void *Mem)
FreeListBucket[Bucket] = (struct AllocNode *)MemNode;
}
else
{ /* put it in the big memory freelist */
{
/* put it in the big memory freelist */
#ifdef DEBUG_HEAP
printf("freeing %lx:%d to freelist\n", (unsigned long)Mem, MemNode->Size);
#endif
@ -249,3 +257,4 @@ void HeapFreeMem(void *Mem)
}
#endif
}

View file

@ -14,7 +14,7 @@
#define HEAP_SIZE 16384 /* default space for the heap and the stack */
#endif
#define LARGE_INT_POWER_OF_TEN 1000000000 /* the largest power of ten which fits in an int on this architecture */
#define ARCH_ALIGN_WORDSIZE sizeof(int) /* memory alignment boundary on this architecture */
#define ARCH_ALIGN_WORDSIZE sizeof(void *) /* memory alignment boundary on this architecture */
#define GLOBAL_TABLE_SIZE 97 /* global variable table */
#define STRING_TABLE_SIZE 97 /* shared string table size */