heap.c File Reference
VM Heap.
More...
#include "pm.h"
Go to the source code of this file.
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.
Define Documentation
#define HEAP_MAX_FREE_CHUNK_SIZE 65532 |
The maximum size a free chunk can be (a free chunk is one that is not in use). The free chunk size is limited by the size field in the *heap* descriptor. That field is fourteen bits with two assumed least significant bits (zeros): (0x3FFF << 2) == 65532
Definition at line 58 of file heap.c.
#define HEAP_MAX_LIVE_CHUNK_SIZE 2044 |
The maximum size a live chunk can be (a live chunk is one that is in use). The live chunk size is limited by the size field in the *object* descriptor. That field is nine bits with two assumed least significant bits (zeros): (0x1FF << 2) == 2044
Definition at line 50 of file heap.c.
#define HEAP_MIN_CHUNK_SIZE ((sizeof(PmHeapDesc_t) + 3) & ~3) |
The minimum size a chunk can be (rounded up to a multiple of 4)
Definition at line 61 of file heap.c.
#define HEAP_NUM_TEMP_ROOTS 24 |
Checks for heap size definition. The size of the temporary roots stack
Definition at line 42 of file heap.c.
#define OBJ_GET_GCVAL |
( |
pobj |
|
) |
((((pPmObj_t)pobj)->od >> OD_MARK_SHIFT) & 1) |
Gets the GC's mark bit for the object. This MUST NOT be called on objects that are free.
Definition at line 68 of file heap.c.
#define OBJ_SET_GCVAL |
( |
pobj, |
|
|
gcval |
|
) |
|
Sets the GC's mark bit for the object This MUST NOT be called on objects that are free.
Definition at line 83 of file heap.c.
Typedef Documentation
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[9:2] | S := Size of the chunk (2 LSbs dropped)
* +-+-+-----------+ F := Chunk free bit (not in use)
* |F|R| S[15:10] | R := Bit reserved for future use
* +-+-+-----------+
* | P(L) | P := hd_prev: Pointer to previous node
* | P(H) | N := hd_next: Pointer to next node
* | N(L) |
* | N(H) | Theoretical min size == 6
* +---------------+ Effective min size == 8
* | unused space | (12 on 32-bit MCUs)
* ... ...
* | end chunk |
* +---------------+
*
Function Documentation
Places the chunk back in the heap.
- Parameters:
-
| ptr | Pointer to object to free. |
Definition at line 549 of file heap.c.
void heap_gcPopTempRoot |
( |
uint8_t |
objid |
) |
|
Pops from the temporary roots stack all objects upto and including the one denoted by the given ID
- Parameters:
-
| objid | ID of object to pop |
Definition at line 1184 of file heap.c.
Pushes an object onto the temporary roots stack if there is room to protect the objects from a potential garbage collection
- Parameters:
-
| pobj | Object to push onto the roots stack |
| r_objid | By reference; ID to use when popping the object from the stack |
Definition at line 1183 of file heap.c.
- Returns:
- Return number of bytes available in the heap
Definition at line 578 of file heap.c.
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
Definition at line 498 of file heap.c.
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
Definition at line 419 of file heap.c.
Initializes the heap for use.
- Returns:
- nothing.
Definition at line 352 of file heap.c.
Variable Documentation
The PyMite heap
Definition at line 160 of file heap.c.