Toy 1.1.6
The Toy programming language is an imperative bytecode-intermediate embedded scripting language
Loading...
Searching...
No Matches
toy_memory.h
Go to the documentation of this file.
1
7#ifndef TOY_MEMORY_H_
8#define TOY_MEMORY_H_
9
10#include <stddef.h>
11
12#include "toy_common.h"
13
19#define TOY_GROW_CAPACITY(capacity) ((capacity) < 8 ? 8 : (capacity) * 2)
20
26#define TOY_GROW_CAPACITY_FAST(capacity) ((capacity) < 32 ? 32 : (capacity) * 2)
27
34#define TOY_ALLOCATE(type, count) ((type*)Toy_reallocate(NULL, 0, sizeof(type) * (count)))
35
41#define TOY_FREE(type, pointer) Toy_reallocate(pointer, sizeof(type), 0)
42
48#define TOY_FREE_ARRAY(type, pointer, oldCount) Toy_reallocate((type*)pointer, sizeof(type) * (oldCount), 0)
49
55#define TOY_GROW_ARRAY(type, pointer, oldCount, count) (type*)Toy_reallocate((type*)pointer, sizeof(type) * (oldCount), sizeof(type) * (count))
56
63#define TOY_SHRINK_ARRAY(type, pointer, oldCount, count) (type*)Toy_reallocate((type*)pointer, sizeof(type) * (oldCount), sizeof(type) * (count))
64
65//implementation details
75TOY_API void* Toy_reallocate(void *pointer, size_t oldSize, size_t newSize);
76
77//assign the memory allocator
92typedef void* (*Toy_MemoryAllocatorFn)(void *pointer, size_t oldSize, size_t newSize);
93
102
103#endif /* TOY_MEMORY_H_ */
void *(* Toy_MemoryAllocatorFn)(void *pointer, size_t oldSize, size_t newSize)
This function interface is used for defining any memory allocator functions. Any and all memory alloc...
Definition: toy_memory.h:92
TOY_API void Toy_setMemoryAllocator(Toy_MemoryAllocatorFn)
Sets the memory allocator, replacing the default memory allocator. This function also overwrites any ...
TOY_API void * Toy_reallocate(void *pointer, size_t oldSize, size_t newSize)
Wraps a call to the internal assigned memory allocator. This function shouldn't be called directly....