/* The following two lines have cause problems for some older ZiLog * compilers in the past (but not the more recent). Life is easier if we * just the suppress them altogther for those tools. */
/* If the MCU handles wide addresses but the memory manager is configured * for a small heap, then verify that the caller is not doing something * crazy. */
/* Add the size of this region to the total size of the heap */
heap->mm_heapsize += heapsize;
/* Create two "allocated" guard nodes at the beginning and end of * the heap. These only serve to keep us from allocating outside * of the heap. * * And create one free node between the guard nodes that contains * all available memory. */
structmm_allocnode_s { mmsize_t size; /* Size of this chunk */ mmsize_t preceding; /* Size of the preceding chunk */ };
1 2 3 4 5 6 7
structmm_freenode_s { mmsize_t size; /* Size of this chunk */ mmsize_t preceding; /* Size of the preceding chunk */ structmm_freenode_s *flink;/* Supports a doubly linked list */ structmm_freenode_s *blink; };
for (prev = &heap->mm_nodelist[ndx], next = heap->mm_nodelist[ndx].flink; next && next->size && next->size < node->size; prev = next, next = next->flink);
#if defined(CONFIG_MM_SMALL) && UINTPTR_MAX <= UINT32_MAX /* Two byte offsets; Pointers may be 2 or 4 bytes; * sizeof(struct mm_freenode_s) is 8 or 12 bytes. * REVISIT: We could do better on machines with 16-bit addressing. */
/* Chunk Header Definitions *************************************************/ /* These definitions define the characteristics of allocator * * MM_MIN_SHIFT is used to define MM_MIN_CHUNK. * MM_MIN_CHUNK - is the smallest physical chunk that can * be allocated. It must be at least a large as * sizeof(struct mm_freenode_s). Larger values may * improve performance slightly, but will waste memory * due to quantization losses. * * MM_MAX_SHIFT is used to define MM_MAX_CHUNK * MM_MAX_CHUNK is the largest, contiguous chunk of memory * that can be allocated. It can range from 16-bytes to * 4Gb. Larger values of MM_MAX_SHIFT can cause larger * data structure sizes and, perhaps, minor performance * losses. */