forked from parrot/parrot
/
memory.c
73 lines (65 loc) · 1.39 KB
/
memory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* memory.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
* $Id$
* Overview:
* The memory (mem) API handles memory allocation
* Data Structure and Algorithms:
* History:
* Notes:
* References:
*/
#include "parrot/parrot.h"
/*=for api mem mem_sys_allocate
uses malloc to allocate system memory
*/
void *
mem_sys_allocate(size_t size)
{
return malloc((size_t)size);
}
/*=for api mem mem_sys_allocate_zeroed
uses calloc to allocate system memory
*/
void *
mem_sys_allocate_zeroed(size_t size)
{
return calloc(1, (size_t)size);
}
/*=for api mem mem_sys_realloc
resize a chunk of system memory
*/
void *
mem_sys_realloc(void *from, size_t size)
{
return realloc(from, size);
}
/*=for api mem mem_sys_free
free a chunk of memory back to the system
*/
void
mem_sys_free(void *from)
{
free(from);
}
/*=for api mem mem_setup_allocator
initializes the allocator
*/
void
mem_setup_allocator(struct Parrot_Interp *interpreter)
{
interpreter->arena_base = mem_sys_allocate(sizeof(struct Arenas));
interpreter->arena_base->sized_header_pools = NULL;
interpreter->arena_base->num_sized = 0;
Parrot_initialize_memory_pools(interpreter);
Parrot_initialize_header_pools(interpreter);
}
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/