#include "pm.h"
Classes | |
struct | PmHeapDesc_s |
struct | PmHeap_s |
Defines | |
#define | __FILE_ID__ 0x06 |
#define | HEAP_MAX_LIVE_CHUNK_SIZE 2044 |
#define | HEAP_MAX_FREE_CHUNK_SIZE 65532 |
#define | HEAP_MIN_CHUNK_SIZE ((sizeof(PmHeapDesc_t) + 3) & ~3) |
#define | OBJ_GET_GCVAL(pobj) ((((pPmObj_t)pobj)->od >> OD_MARK_SHIFT) & 1) |
#define | OBJ_SET_GCVAL(pobj, gcval) |
Typedefs | |
typedef struct PmHeapDesc_s | PmHeapDesc_t |
typedef struct PmHeapDesc_s * | pPmHeapDesc_t |
typedef struct PmHeap_s | PmHeap_t |
typedef struct PmHeap_s * | pPmHeap_t |
Functions | |
PmReturn_t | heap_init (void) |
PmReturn_t | heap_getChunk (uint16_t requestedsize, uint8_t **r_pchunk) |
PmReturn_t | heap_freeChunk (pPmObj_t ptr) |
uint16_t | heap_getAvail (void) |
VM heap operations. All of PyMite's dynamic memory is obtained from this heap. The heap provides dynamic memory on demand.
#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
#define HEAP_MAX_LIVE_CHUNK_SIZE 2044 |
Checks for heap size definition. 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
#define HEAP_MIN_CHUNK_SIZE ((sizeof(PmHeapDesc_t) + 3) & ~3) |
The minimum size a chunk can be (rounded up to a multiple of 4)
#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.
#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.
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[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 | +---------------+
PmReturn_t heap_freeChunk | ( | pPmObj_t | ptr | ) |
Places the chunk back in the heap.
ptr | Pointer to object to free. |
uint16_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.
requestedsize | Requested size of the chunk in bytes. | |
r_pchunk | Addr of ptr to chunk (return). |
PmReturn_t heap_init | ( | void | ) |
Initializes the heap for use.