39 lines
743 B
C
39 lines
743 B
C
#define MAX_PERM_BLOCK 131072
|
|
|
|
/*
|
|
* Allocate some permanent memory.
|
|
* Permanent memory is never freed,
|
|
* pointers into it may be copied safely.
|
|
*/
|
|
void *alloc_perm( int sMem )
|
|
{
|
|
static char *pMemPerm;
|
|
static int iMemPerm;
|
|
void *pMem;
|
|
|
|
while ( sMem % sizeof(long) != 0 )
|
|
sMem++;
|
|
if ( sMem > MAX_PERM_BLOCK )
|
|
{
|
|
printf("\n\rAlloc_perm: %d too large.", sMem );
|
|
exit( 1 );
|
|
}
|
|
|
|
if ( pMemPerm == NULL || iMemPerm + sMem > MAX_PERM_BLOCK )
|
|
{
|
|
iMemPerm = 0;
|
|
if ( ( pMemPerm = calloc( 1, MAX_PERM_BLOCK ) ) == NULL )
|
|
{
|
|
perror( "Alloc_perm" );
|
|
exit( 1 );
|
|
}
|
|
}
|
|
|
|
pMem = pMemPerm + iMemPerm;
|
|
iMemPerm += sMem;
|
|
// nAllocPerm += 1;
|
|
// sAllocPerm += sMem;
|
|
return pMem;
|
|
}
|
|
|