r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

BrianH
24-Mar-2009
[13022]
Steeve, you can put ^(00) in strings in R2 and R3. They get converted 
to null-terminated for calling C routines, but they aren't internally.
[unknown: 5]
24-Mar-2009
[13023]
But sticking to R2 and putting aside conversion to c routines, are 
you saying that R2 doesn't terminate strings with null?
Steeve
24-Mar-2009
[13024]
hum... internally, strings are null terminated, i don't know the 
use, but it's a fact
BrianH
24-Mar-2009
[13025x2]
Yes.
Steeve, have you disassembled REBOL?
Steeve
24-Mar-2009
[13027x2]
not fully
some parts
[unknown: 5]
24-Mar-2009
[13029x2]
Well the use for terminating the strings would be for determining 
length.  Otherwise you would have to determine length by updating 
the length value on each change of the string.
Which is what I hope is that case actually.
Steeve
24-Mar-2009
[13031x2]
Paul, there are the two of them: length is stored, but strings are 
null terminated
iirc
BrianH
24-Mar-2009
[13033]
Steeve, you can put nulls in the middle of strings and their length 
doesn't change. Thus, not null terminated.
Steeve
24-Mar-2009
[13034]
i know it's not used, but really i saw nulls at the end of strings
BrianH
24-Mar-2009
[13035]
They may have nulls tacked on the end after the tail of the string 
for C compatibility, but REBOL doesn't use them.
Steeve
24-Mar-2009
[13036]
i agree
[unknown: 5]
24-Mar-2009
[13037]
Is there another form of termination that might not be nulls that 
REBOL uses?
BrianH
24-Mar-2009
[13038x2]
Otherwise length? would be O(n), and my testing has found it to be 
O(1) for avery series type except list!
REBOL uses something like Pascal strings with nulls tacked on the 
end for C compatibility. The length is tracked on write.
[unknown: 5]
24-Mar-2009
[13040x2]
Well, if REBOL allocates storage for a string then there might be 
a maxlength value stored along with a length value.
Such that length? is returning current length.
Steeve
24-Mar-2009
[13042x3]
A string use several slots of 16 bytes length.
by default, an empty string uses one slot (16 bytes).

If you define a string of 16 bytes length. then, the string uses 
2 slots because the null char at the end of the string can fit in 
the first slot.
*(can't fit)
They are continous slots of course
BrianH
24-Mar-2009
[13045]
Are you referring to R2 or R3? R3's strings are different.
Steeve
24-Mar-2009
[13046]
R2
BrianH
24-Mar-2009
[13047]
Right.
[unknown: 5]
24-Mar-2009
[13048]
I'm curious why your saying it is 16 bytes.
BrianH
24-Mar-2009
[13049]
Strings are preallocated in multiples of 16 bytes, probably to simplify 
the GC.
[unknown: 5]
24-Mar-2009
[13050]
Oh this is a REBOL thing.
Steeve
24-Mar-2009
[13051]
all values in Rebol are chunked into slots of 16 bytes length
[unknown: 5]
24-Mar-2009
[13052x2]
Got ya.
Seems a waste.
Steeve
24-Mar-2009
[13054]
all series data type are using continuous slots
BrianH
24-Mar-2009
[13055]
Memory management. Even the stack is a block.
[unknown: 5]
24-Mar-2009
[13056]
I'm just thinkg of the memory storage.  It seems a waste from that 
persective.
Steeve
24-Mar-2009
[13057x3]
we no that, it's a choice
*we know
speed vs memory
BrianH
24-Mar-2009
[13060]
All memory management systems have a little waste. You have to balance 
the memory overhead versus the CPU overhead.
[unknown: 5]
24-Mar-2009
[13061]
I'm not sure how it is faster.
Steeve
24-Mar-2009
[13062]
its faster to handle blocks
BrianH
24-Mar-2009
[13063]
It is faster to allocate in chunks because you don't have to reallocate 
as often.
[unknown: 5]
24-Mar-2009
[13064]
I suppose Carl has something more being allocated then just the string 
data.
BrianH
24-Mar-2009
[13065]
(bbl)
[unknown: 5]
24-Mar-2009
[13066]
So I'm wondering where the length is stored at.  I'm wondering if 
it is stored preceding the string data.
Steeve
24-Mar-2009
[13067x2]
no, it's stored in another one slot, anywher in the mmemory
by default, an empty string allocate 3 slots.
1 storing the logical address
1 storing the physical address and the length
1 storing storing the real data .

These slots can be stored at any place
[unknown: 5]
24-Mar-2009
[13069]
interesting.  But doesn't seem very efficient.
Steeve
24-Mar-2009
[13070]
when a string is expanded,  the data can be moved in another one 
place.
So the physical address slot is updated, not the logical one
[unknown: 5]
24-Mar-2009
[13071]
Well this is where I have the concern.  Because at a lower level 
you would want to allocate memory for string large enough for certain 
variations of the string during runtime.  And that approach seems 
to negate that  possibility.