python-on-a-chip online compiler
VM Heap. More...
Go to the source code of this file.
Typedefs | |
typedef struct PmHeapDesc_s | PmHeapDesc_t |
The following is a diagram of the heap descriptor at the head of the chunk: | |
Functions | |
static void | heap_dump (void) |
DEBUG: dumps the heap and roots list to a file. | |
PmReturn_t | heap_init (uint8_t *base, uint32_t size) |
Initializes the heap for use. | |
static PmReturn_t | heap_getChunkImpl (uint16_t size, uint8_t **r_pchunk) |
Obtains a chunk of memory from the free list. | |
PmReturn_t | heap_getChunk (uint16_t requestedsize, uint8_t **r_pchunk) |
Returns a free chunk from the heap. | |
PmReturn_t | heap_freeChunk (pPmObj_t ptr) |
Places the chunk back in the heap. | |
uint32_t | heap_getAvail (void) |
uint32_t | heap_getSize (void) |
static PmReturn_t | heap_purgeStringCache (uint8_t gcval) |
Unlinks free objects from the string cache. | |
PmReturn_t | heap_gcRun (void) |
Runs the mark-sweep garbage collector. | |
PmReturn_t | heap_gcSetAuto (uint8_t auto_gc) |
Enables (if true) or disables automatic garbage collection. | |
void | heap_gcPushTempRoot (pPmObj_t pobj, uint8_t *r_objid) |
Pushes an object onto the temporary roots stack if there is room to protect the objects from a potential garbage collection. | |
void | heap_gcPopTempRoot (uint8_t objid) |
Pops from the temporary roots stack all objects upto and including the one denoted by the given ID. | |
Variables | |
static PmHeap_t pmHeap | PM_PLAT_HEAP_ATTR |
The PyMite heap. |
Detailed Description
VM Heap.
VM heap operations. All of PyMite's dynamic memory is obtained from this heap. The heap provides dynamic memory on demand.
Definition in file heap.c.
Typedef Documentation
typedef struct PmHeapDesc_s PmHeapDesc_t |
The following is a diagram of the heap descriptor at the head of the chunk:
* MSb LSb * 7 6 5 4 3 2 1 0 * pchunk-> +-+-+-+-+-+-+-+-+ S := Size of the chunk (2 LSbs dropped) * | S |F|R| F := Chunk free bit (not in use) * +-----------+-+-+ R := Bit reserved for future use * | S | * +---------------+ * | P(L) | P := hd_prev: Pointer to previous node * | P(H) | N := hd_next: Pointer to next node * | N(L) | * | N(H) | * +---------------+ * | unused space | * ... ... * | end chunk | * +---------------+ *
On an 8-bit MCU with 16-bit addresses, the theoretical minimum size of the heap descriptor is 6 bytes. The effective size (due to pointer alignment) is usually 8 bytes. On an MCU with 32-bit addresses, the heap descriptor's size is 12 bytes.
Function Documentation
static void heap_dump | ( | void | ) | [static] |
PmReturn_t heap_freeChunk | ( | pPmObj_t | ptr ) |
void heap_gcPopTempRoot | ( | uint8_t | objid ) |
void heap_gcPushTempRoot | ( | pPmObj_t | pobj, |
uint8_t * | r_objid | ||
) |
PmReturn_t heap_gcRun | ( | void | ) |
PmReturn_t heap_gcSetAuto | ( | uint8_t | auto_gc ) |
uint32_t heap_getAvail | ( | void | ) |
PmReturn_t heap_getChunk | ( | uint16_t | requestedsize, |
uint8_t ** | r_pchunk | ||
) |
Returns a free chunk from the heap.
The chunk will be at least the requested size. The actual size can be found in the return chunk's od.od_size.
- Parameters:
-
requestedsize Requested size of the chunk in bytes. r_pchunk Addr of ptr to chunk (return).
- Returns:
- Return code
static PmReturn_t heap_getChunkImpl | ( | uint16_t | size, |
uint8_t ** | r_pchunk | ||
) | [static] |
Obtains a chunk of memory from the free list.
Performs the Best Fit algorithm. Iterates through the freelist to see if a chunk of suitable size exists. Shaves a chunk to perfect size iff the remainder is greater than the minimum chunk size.
- Parameters:
-
size Requested chunk size r_pchunk Return ptr to chunk
- Returns:
- Return status
uint32_t heap_getSize | ( | void | ) |
PmReturn_t heap_init | ( | uint8_t * | base, |
uint32_t | size | ||
) |
static PmReturn_t heap_purgeStringCache | ( | uint8_t | gcval ) | [static] |
Unlinks free objects from the string cache.
This function must only be called by the GC after the heap has been marked and before the heap has been swept.
This solves the problem where a string object would be collected but its chunk was still linked into the free list
- Parameters:
-
gcval The current value for chunks marked by the GC
Variable Documentation
PmHeap_t pmHeap PM_PLAT_HEAP_ATTR [static] |
Generated on Tue Jul 12 2022 23:13:47 by 1.7.2