Skip to content

Commit

Permalink
FIX: rounding function for memory allocation needs. Now passing all R…
Browse files Browse the repository at this point in the history
…ed runtime tests.
  • Loading branch information
dockimbel committed Mar 14, 2012
1 parent f3bfeb6 commit ee8099a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion red/runtime/allocator.reds
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ alloc-series-buffer: func [
/local series frame sz
][
assert positive? size ;-- size is not zero or negative
size: round-to size 16 ;-- size is a multiple of 16 (one cell! size)
size: round-to-next size 16 ;-- size is a multiple of 16 (one cell! size)

frame: memory/s-active
sz: size + size? series-buffer! ;-- add series header size
Expand Down
12 changes: 12 additions & 0 deletions red/runtime/utils.reds
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ round-to: func [
size [integer!] ;-- a memory region size
scale [integer!] ;-- scale parameter
return: [integer!] ;-- nearest scale multiple
][
assert scale <> 0
(size - 1 + scale) and (negate scale)
]

;-------------------------------------------
;-- Return an integer rounded to the next nearest multiple of scale parameter
;-------------------------------------------
round-to-next: func [
size [integer!] ;-- a memory region size
scale [integer!] ;-- scale parameter
return: [integer!] ;-- nearest scale multiple
][
assert scale <> 0
(size + scale) and (negate scale)
Expand Down

0 comments on commit ee8099a

Please sign in to comment.