diff --git a/plugins/primus_lisp/lisp/simple-memory-allocator.lisp b/plugins/primus_lisp/lisp/simple-memory-allocator.lisp index 67d97873e..6d4613794 100644 --- a/plugins/primus_lisp/lisp/simple-memory-allocator.lisp +++ b/plugins/primus_lisp/lisp/simple-memory-allocator.lisp @@ -18,10 +18,20 @@ (defparameter *malloc-guard-pattern* 0xA5 "a byte that will be used to fill guard edges") - (defparameter *malloc-zero-sentinel* 0 "a pointer that is returned by (malloc 0)") +(defparameter *malloc-initialize-memory* false + "if true then initialize allocated memory with *malloc-initial-value*") + +(defparameter *malloc-initial-value* 0 + "initialize allocated memory with the said value") + +(defun memory/allocate (ptr len) + (if *malloc-initialize-memory* + (memory-allocate ptr n *malloc-initial-value*) + (memory-allocate ptr n))) + (defun malloc (n) "allocates a memory region of size N" (declare (external "malloc")) @@ -29,12 +39,13 @@ (if (malloc-will-reach-limit n) 0 (let ((n (+ n (* 2 *malloc-guard-edges*))) (ptr brk) - (failed (memory-allocate ptr n 0))) + (failed (memory/allocate ptr n))) (if failed 0 (set brk (+ brk n)) (malloc/fill-edges ptr n) (+ ptr *malloc-guard-edges*)))))) + ;; in our simplistic malloc implementation, free is just a nop (defun free (p) "frees the memory region pointed by P"