/* * Initializes the heap state variables */ PmReturn_t heap_init(void) { pPmHeapDesc_t pchunk; /* Create one big chunk */ pchunk = (pPmHeapDesc_t)pmHeap.base; OBJ_SET_FREE(pchunk, 1); OBJ_SET_SIZE(pchunk, HEAP_SIZE); pchunk->next = C_NULL; pchunk->prev = C_NULL; /* Init heap globals */ pmHeap.pfreelist = pchunk; pmHeap.avail = HEAP_SIZE; pmHeap.gcval = (uint8_t)0; pmHeap.auto_gc = C_TRUE; C_DEBUG_PRINT(VERBOSITY_LOW, "heap_init(), id=%p, s=%d\n", pmHeap.base, HEAP_SIZE); string_cacheInit(); return PM_RET_OK; }
/* * Initializes the heap state variables */ PmReturn_t heap_init(void) { pPmHeapDesc_t pchunk; #if PM_HEAP_SIZE > 65535 uint32_t hs; #else uint16_t hs; #endif #if __DEBUG__ /* Fill the heap with a non-NULL value to bring out any heap bugs. */ sli_memset(pmHeap.base, 0xAA, sizeof(pmHeap.base)); #endif /* Init heap globals */ pmHeap.pfreelist = C_NULL; pmHeap.avail = 0; #ifdef HAVE_GC pmHeap.gcval = (uint8_t)0; pmHeap.temp_root_index = (uint8_t)0; heap_gcSetAuto(C_TRUE); #endif /* HAVE_GC */ /* Create as many max-sized chunks as possible in the freelist */ for (pchunk = (pPmHeapDesc_t)pmHeap.base, hs = PM_HEAP_SIZE; hs >= HEAP_MAX_FREE_CHUNK_SIZE; hs -= HEAP_MAX_FREE_CHUNK_SIZE) { OBJ_SET_FREE(pchunk, 1); OBJ_SET_SIZE(pchunk, HEAP_MAX_FREE_CHUNK_SIZE); heap_linkToFreelist(pchunk); pchunk = (pPmHeapDesc_t)((uint8_t *)pchunk + HEAP_MAX_FREE_CHUNK_SIZE); } /* Add any leftover memory to the freelist */ if (hs >= HEAP_MIN_CHUNK_SIZE) { /* Round down to a multiple of four */ hs = hs & ~3; OBJ_SET_FREE(pchunk, 1); OBJ_SET_SIZE(pchunk, hs); heap_linkToFreelist(pchunk); } C_DEBUG_PRINT(VERBOSITY_LOW, "heap_init(), id=%p, s=%d\n", pmHeap.base, pmHeap.avail); string_cacheInit(); return PM_RET_OK; }