2 Copyright (C) 2001-2006, The Perl Foundation.
7 src/memory.c - Memory allocation
11 The memory (mem) API handles memory allocation,
13 Basically just a wrapper C<around malloc/calloc/realloc/free()> with an
14 setup function to initialize the memory pools.
24 #include "parrot/parrot.h"
32 mem_sys_allocate(size_t size)>
34 Uses C<malloc> to allocate system memory.
41 mem_sys_allocate(size_t size
)
43 void * const ptr
= malloc((size_t)size
);
44 #ifdef DETAIL_MEMORY_DEBUG
45 fprintf(stderr
, "Allocated %i at %p\n", size
, ptr
);
53 mem__internal_allocate(size_t size
, const char *file
, int line
)
55 void * const ptr
= malloc((size_t)size
);
56 #ifdef DETAIL_MEMORY_DEBUG
57 fprintf(stderr
, "Internal malloc %i at %p (%s/%d)\n",
58 size
, ptr
, file
, line
);
68 mem_sys_allocate_zeroed(size_t size)>
70 Uses C<calloc> to allocate system memory.
77 mem_sys_allocate_zeroed(size_t size
)
79 void * const ptr
= calloc(1, (size_t)size
);
80 #ifdef DETAIL_MEMORY_DEBUG
81 fprintf(stderr
, "Allocated %i at %p\n", size
, ptr
);
89 mem__internal_allocate_zeroed(size_t size
, const char *file
, int line
)
91 void * const ptr
= calloc(1, (size_t)size
);
92 #ifdef DETAIL_MEMORY_DEBUG
93 fprintf(stderr
, "Internal malloc %i at %p (%s/%d)\n",
94 size
, ptr
, file
, line
);
104 mem_sys_realloc(void *from, size_t size)>
106 Resize a chunk of system memory.
113 mem__sys_realloc(void *from
, size_t size
)
116 #ifdef DETAIL_MEMORY_DEBUG
117 fprintf(stderr
, "Freed %p (realloc -- %i bytes)\n", from
, size
);
119 ptr
= realloc(from
, size
);
120 #ifdef DETAIL_MEMORY_DEBUG
121 fprintf(stderr
, "Allocated %i at %p\n", size
, ptr
);
129 mem__internal_realloc(void *from
, size_t size
, const char *file
, int line
)
131 void * const ptr
= realloc(from
, size
);
132 #ifdef DETAIL_MEMORY_DEBUG
133 fprintf(stderr
, "internal free of %p (realloc -- %i bytes) (%s/%d)\n",
134 from
, size
, file
, line
);
135 fprintf(stderr
, "Internal malloc %i at %p (%s/%d)\n",
136 size
, ptr
, file
, line
);
147 mem_sys_free(void *from)>
149 Free a chunk of memory back to the system.
156 mem_sys_free(void *from
)
158 #ifdef DETAIL_MEMORY_DEBUG
159 fprintf(stderr
, "Freed %p\n", from
);
166 mem__internal_free(void *from
, const char *file
, int line
)
168 #ifdef DETAIL_MEMORY_DEBUG
169 fprintf(stderr
, "Internal free of %p (%s/%d)\n", from
, file
, line
);
177 mem_setup_allocator(Interp *interp)>
179 Initializes the allocator.
186 mem_setup_allocator(Interp
*interp
)
188 interp
->arena_base
= mem_sys_allocate_zeroed(sizeof (struct Arenas
));
189 SET_NULL(interp
->arena_base
->sized_header_pools
);
192 Parrot_gc_ms_init(interp
);
195 Parrot_gc_ims_init(interp
);
198 Parrot_gc_gms_init(interp
);
201 Parrot_initialize_memory_pools(interp
);
202 Parrot_initialize_header_pools(interp
);
217 * c-file-style: "parrot"
219 * vim: expandtab shiftwidth=4: