memory.h
Go to the documentation of this file.
1 #pragma once
6 #include "kuroko.h"
7 #include "object.h"
8 #include "table.h"
9 
10 #define KRK_GROW_CAPACITY(c) ((c) < 8 ? 8 : (c) * 2)
11 #define KRK_GROW_ARRAY(t,p,o,n) (t*)krk_reallocate(p,sizeof(t)*o,sizeof(t)*n)
12 #define KRK_FREE_ARRAY(t,a,c) krk_reallocate(a,sizeof(t) * c, 0)
13 #define KRK_ALLOCATE(type, count) (type*)krk_reallocate(NULL,0,sizeof(type)*(count))
14 
27 extern void * krk_reallocate(void * ptr, size_t old, size_t new);
28 
35 extern void krk_freeObjects(void);
36 
46 extern size_t krk_collectGarbage(void);
47 
57 extern void krk_markValue(KrkValue value);
58 
66 extern void krk_markObject(KrkObj * object);
67 
76 extern void krk_markTable(KrkTable * table);
77 
89 extern void krk_gcTakeBytes(const void * ptr, size_t size);
Top-level header with configuration macros.
void krk_markValue(KrkValue value)
During a GC scan cycle, mark a value as used.
Definition: memory.c:334
void krk_markTable(KrkTable *table)
During a GC scan cycle, mark the contents of a table as used.
Definition: memory.c:444
void krk_freeObjects(void)
Release all objects.
Definition: memory.c:277
void krk_markObject(KrkObj *object)
During a GC scan cycle, mark an object as used.
Definition: memory.c:321
void * krk_reallocate(void *ptr, size_t old, size_t new)
Resize an allocated heap object.
Definition: memory.c:157
void krk_gcTakeBytes(const void *ptr, size_t size)
Assume ownership of size bytes at ptr.
Definition: memory.c:149
size_t krk_collectGarbage(void)
Run a cycle of the garbage collector.
Definition: memory.c:514
Struct definitions for core object types.
The most basic object type.
Definition: object.h:41
Simple hash table of arbitrary keys to values.
Definition: table.h:28
Stack reference or primative value.
Implementation of a generic hash table.