Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WISH: Lower memory use by not counting with byte terminator in the Make_Binary function. #2480

Open
Oldes opened this issue Jan 14, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@Oldes
Copy link
Owner

Oldes commented Jan 14, 2022

Currently when Make_Binary C function is called, it requires 1 more byte.

But as the memory is allocated from pools, it actually uses double memory (usually), just because of this reserved space for the terminator byte. It can be demonstrated in the debug builds using the dump function. For example:

bin: make binary! 32
dump/fmt bin
;=> Series #EC18C740: wide: 1  size: 64     bias: 0 tail: 0 rest: 64 flags: #00000001 "-"
bin: make binary! 1024
dump/fmt bin
;=> Series #EC18BD60: wide: 1  size: 2048   bias: 0 tail: 0 rest: 2048 flags: #00000001 "-"

Notice the size: 64 and size: 2048. The reason is, that we actually need to allocate 33 and 1025 bytes now, and the nearest memory pool sizes for such values are these 64 and 2048. Old rebolers knew that and have been using size 1 less, but that is ugly and strange.

I suppose that the terminator byte is a leftover from Rebol2, where it was possible to coerce binary to string without encoding using as-string. This is not allowed anymore and so the terminator should not be required when making a binary with an exact size.

@Oldes Oldes added the enhancement New feature or request label Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant