-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
gc.cr
76 lines (63 loc) · 1.63 KB
/
gc.cr
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
74
75
76
# :nodoc:
fun __crystal_malloc(size : UInt32) : Void*
GC.malloc(LibC::SizeT.new(size))
end
# :nodoc:
fun __crystal_malloc_atomic(size : UInt32) : Void*
GC.malloc_atomic(LibC::SizeT.new(size))
end
# :nodoc:
fun __crystal_realloc(pointer : Void*, size : UInt32) : Void*
GC.realloc(pointer, LibC::SizeT.new(size))
end
# :nodoc:
fun __crystal_malloc64(size : UInt64) : Void*
{% if flag?(:bits32) %}
if size > UInt32::MAX
raise ArgumentError.new("Given size is bigger than UInt32::MAX")
end
{% end %}
GC.malloc(LibC::SizeT.new(size))
end
# :nodoc:
fun __crystal_malloc_atomic64(size : UInt64) : Void*
{% if flag?(:bits32) %}
if size > UInt32::MAX
raise ArgumentError.new("Given size is bigger than UInt32::MAX")
end
{% end %}
GC.malloc_atomic(LibC::SizeT.new(size))
end
# :nodoc:
fun __crystal_realloc64(ptr : Void*, size : UInt64) : Void*
{% if flag?(:bits32) %}
if size > UInt32::MAX
raise ArgumentError.new("Given size is bigger than UInt32::MAX")
end
{% end %}
GC.realloc(ptr, LibC::SizeT.new(size))
end
module GC
record Stats,
# collections : LibC::ULong,
# bytes_found : LibC::Long,
heap_size : LibC::ULong,
free_bytes : LibC::ULong,
unmapped_bytes : LibC::ULong,
bytes_since_gc : LibC::ULong,
total_bytes : LibC::ULong
def self.malloc(size : Int)
malloc(LibC::SizeT.new(size))
end
def self.malloc_atomic(size : Int)
malloc_atomic(LibC::SizeT.new(size))
end
def self.realloc(pointer : Void*, size : Int)
realloc(pointer, LibC::SizeT.new(size))
end
end
{% if flag?(:gc_none) %}
require "gc/none"
{% else %}
require "gc/boehm"
{% end %}