27 lines
1.1 KiB
Plaintext
27 lines
1.1 KiB
Plaintext
;;;; (free s) on a slice hands its block back to the context allocator, or to
|
|
;;;; the one named. A slice does not carry its allocator, so a dev build checks
|
|
;;;; the block against the allocation registry and traps rather than hand one
|
|
;;;; allocator another's block. Argument 0 frees correctly both ways; 1 frees
|
|
;;;; an arena's copy through the context allocator; 2 frees one copy twice;
|
|
;;;; 3 frees a view of an array, which no allocator handed out.
|
|
(defn main [args [string]] i32
|
|
(let [which (if (> (length args) 1) (bytes->i64 (bytes-view (at args 1))) 0)
|
|
a (arena-new 4096)]
|
|
(cond
|
|
(= which 1) (let [b (bytes "arena" a)] (free b))
|
|
(= which 2) (let [b (bytes "twice")] (free b) (free b))
|
|
(= which 3) (let [arr [1 2 3]
|
|
s (slice arr)]
|
|
(free s))
|
|
:else
|
|
(let [b (bytes "heap")
|
|
c (bytes "arena" a)
|
|
d (clone (slice [1.5 2.5]) (heap-allocator))]
|
|
(println (string b) (string c) (at d 1))
|
|
(free b)
|
|
(free c a)
|
|
(free d (heap-allocator))))
|
|
(println "done")
|
|
(arena-destroy a))
|
|
0)
|