12 std::size_t total_bytes = size * nobjs;
15 if (bytes_left >= total_bytes) {
20 else if (bytes_left >= size) {
21 nobjs = int(bytes_left/size);
22 total_bytes = size * nobjs;
32 obj * * my_free_list =
40 obj * * my_free_list, *p;
49 *my_free_list = p -> free_list_link;
78 obj * current_obj, * next_obj;
81 if (1 == nobjs)
return chunk;
85 result = (
obj *)chunk;
86 *my_free_list = next_obj = (
obj *)(chunk + n);
88 current_obj = next_obj;
89 next_obj = (
obj *)((
char *)next_obj + n);
91 current_obj -> free_list_link =
nullptr;
95 current_obj -> free_list_link = next_obj;
110 return std::realloc(p, new_sz);
114 copy_sz = new_sz > old_sz? old_sz : new_sz;
115 std::memcpy(result, p, copy_sz);
131 std::strcpy(p,
"fred\n");
132 std::cerr << p <<
'\n';
constexpr std::size_t VNL_ALLOC_NFREELISTS
constexpr std::size_t VNL_ALLOC_MAX_BYTES
static void deallocate(void *p, std::size_t n)
static char * chunk_alloc(std::size_t size, int &nobjs)
constexpr int VNL_ALLOC_ALIGN
static std::size_t heap_size
static void * reallocate(void *p, std::size_t old_sz, std::size_t new_sz)
static std::size_t ROUND_UP(std::size_t bytes)
static obj * free_list[VNL_ALLOC_NFREELISTS]
static std::size_t FREELIST_INDEX(std::size_t bytes)
static void * allocate(std::size_t n)
static void * refill(std::size_t n)