World: r3wp
[Core] Discuss core issues
older newer | first last |
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. |
Steeve 24-Mar-2009 [13072] | each reference on the same strings, have his own logical slot pointing on the same physical slot |
[unknown: 5] 24-Mar-2009 [13073x2] | Not negate it necessarily but make it less efficient asyou would have to allocate storage for the string each time on the new size. |
I'm obviously talking low level here and not what we have ability to do via REBOL. | |
Steeve 24-Mar-2009 [13075] | So basically, the string " " uses (16 * 3) = 48 bytes the char #" " uses 16 bytes Do your choice :-) |
[unknown: 5] 24-Mar-2009 [13076x2] | That seems crazy to me. |
I guess Carl has his reasons. | |
Maxim 24-Mar-2009 [13078x2] | actually all series store these pointers no? |
paul, rebol does mutable series. | |
Steeve 24-Mar-2009 [13080x2] | yest |
*yes | |
Maxim 24-Mar-2009 [13082] | there is no other way... you have to know the bounds, and allow ram to be recycled. indirection is the only way to do this. rebol has its own memory manager. |
Steeve 24-Mar-2009 [13083] | but new references on the same serie only consume a new slot of 16 bytes |
older newer | first last |