packagePo createPkg(char *name, char *version) { packagePo pkg = (packagePo) allocPool(pkgPool); uniCpy((char *) &pkg->packageName, NumberOf(pkg->packageName), name); uniCpy((char *) &pkg->version, NumberOf(pkg->version), version); hashPut(packages, pkg, pkg); return pkg; }
/* allocate and initialize a pool */ static struct GGGGC_Pool *newPool(int mustSucceed) { struct GGGGC_Pool *ret; ret = NULL; /* try to reuse a pool */ if (freePoolsHead) { if (freePoolsHead) { ret = freePoolsHead; freePoolsHead = freePoolsHead->next; if (!freePoolsHead) freePoolsTail = NULL; } } /* otherwise, allocate one */ if (!ret) ret = (struct GGGGC_Pool *) allocPool(mustSucceed); if (!ret) return NULL; /* set it up */ ret->next = NULL; ret->free = ret->start; ret->end = (ggc_size_t *) ((unsigned char *) ret + GGGGC_POOL_BYTES); return ret; }
static triePo emptyTr(char *prefix) { init(); triePo emptyTr = (triePo) allocPool(triePool); emptyTr->prefix = prefix; emptyTr->follows = NULL; emptyTr->value = NULL; return emptyTr; }
/* allocate and initialize a pool */ static struct GGGGC_Pool *newPool(unsigned char gen, int mustSucceed) { struct GGGGC_Pool *ret; #ifdef GGGGC_DEBUG_TINY_HEAP static ggc_thread_local int allocationsLeft = GGGGC_GENERATIONS; if (allocationsLeft-- <= 0) { allocationsLeft = 0; if (mustSucceed) { fprintf(stderr, "GGGGC: exceeded tiny heap size\n"); abort(); } return NULL; } #endif ret = NULL; /* try to reuse a pool */ if (freePoolsHead) { ggc_mutex_lock_raw(&freePoolsLock); if (freePoolsHead) { ret = freePoolsHead; freePoolsHead = freePoolsHead->next; if (!freePoolsHead) freePoolsTail = NULL; } ggc_mutex_unlock(&freePoolsLock); } /* otherwise, allocate one */ if (!ret) ret = (struct GGGGC_Pool *) allocPool(mustSucceed); if (!ret) return NULL; /* set it up */ ret->next = NULL; ret->gen = gen; ret->free = ret->start; ret->end = (ggc_size_t *) ((unsigned char *) ret + GGGGC_POOL_BYTES); #if GGGGC_GENERATIONS > 1 /* clear the remembered set */ if (gen > 0) memset(ret->remember, 0, GGGGC_CARDS_PER_POOL); /* the first object in the first usable card */ ret->firstObject[GGGGC_CARD_OF(ret->start)] = (((ggc_size_t) ret->start) & GGGGC_CARD_INNER_MASK) / sizeof(ggc_size_t); #endif return ret; }
void * nzalloc(MemPool **pmp, int bytes) { MemPool *mp; /* 8 or 16-byte alignment required, depending on the pointer size */ bytes = (bytes + MEMNODE_SIZE_MASK) & ~MEMNODE_SIZE_MASK; for(mp = *pmp; mp != NULL; mp = mp->mp_Next) { if (bytes <= mp->mp_Size - mp->mp_Used) { MemNode **pmn; MemNode *mn; for (pmn = &mp->mp_First; (mn = *pmn) != NULL; pmn = &mn->mr_Next) { if (bytes <= mn->mr_Bytes) { /* * Cut a chunk of memory out of the beginning of this * block and fixup the link appropriately. */ char *ptr = (char *)mn; if (mn->mr_Bytes == bytes) { *pmn = mn->mr_Next; } else { mn = (MemNode *)((char *)mn + bytes); mn->mr_Next = ((MemNode *)ptr)->mr_Next; mn->mr_Bytes = ((MemNode *)ptr)->mr_Bytes - bytes; *pmn = mn; } mp->mp_Used += bytes; return(ptr); } } } } /* * Failed to locate sufficient memory, allocate another * pool. */ allocPool(pmp, ((bytes < POOLSIZE) ? POOLSIZE : bytes)); return(zalloc(pmp, bytes)); }
void *CMEM_allocPool2(int blockid, int poolid, CMEM_AllocParams *params) { return allocPool(blockid, poolid, params); }
void *CMEM_allocPool(int poolid, CMEM_AllocParams *params) { return allocPool(0, poolid, params); }