[REBOL] Re: TUPLE! DATA-MODEL & OTHER VALUES
From: larry:ecotope at: 12-Jun-2001 12:12
Hi Holger,
> What IS safe to say is:
>
> "Simple" types (integer, decimal, time etc.) only take up a small amount
of memory and
> have "copy" semantics.
>
> More complex types, in particular those that have a variable size (series,
object,
> function) or complicated underlying data structures (port), but also some
fixed-size
> types which are quite large (e.g. bitset) always consist of two parts: the
value
> part and the "data" part. The "value" part is unique for each value and
conceptually
> references (points to) the "data" part. The "data" part is what is shared
by several
> values and is subject to garbage collection. For a series, e.g., the value
part contains
> the index, and the data part contains everything else, i.e. the series
contents, its
> length etc.
>
> What started this discussion was the behavior of the tuple! datatype. In
REBOL a
> tuple! value is considered "simple". That's why its length is limited and
why there
> is no underlying "data" that can be changed. A tuple! is not a series!,
even though
> it is a linear sequence of items, like a series!, and supports some of the
same syntax.
Thanks Holger, that is very useful information. I am still a bit puzzled by
the apparent memory allocation for blocks.
Using REBOL/Core 2.5.0.3.1
>> start: system/stats
== 1620752
>> b: make block! 10000
== []
>> system/stats - start / 10000
== 16.1792
>> loop 10000 [insert tail b to-decimal random 1000]
== []
>> system/stats - start / 10000
== 16.1792
>> b
== [695 852 380 196 367 232 853 912 304 415 171 632 767 530 257 786 935 620
566 441
445 704 719 260 715 897 556 599 936 666 728 199...
>> type? first b
== decimal!
It seems like there are about 16 bytes allocated per element when the empty
block is created, but when I insert 10000 decimal! values at a minimum of 8
bytes per element into it, the memory allocation does not increase.
Does this imply the "pointers" for the block elements have room somewhere
for short simple types, or does the block creation simply allocate a certain
amount of space for short simple values?
Are the values of simple block elements stored consecutively in memory, or
does the block just contain "pointers" to values in the heap?
Any comments would be much appreciated.
-Larry