Posted: Tue Dec 31, 2002 2:51 am
Restored from previous forum. Originally posted by Danilo.
I also thought *c.s is a pointer to a string, because '*' means
_always_ pointer in the PureBasic language.
In my opinion, the whole string stuff in PB isnt very good
and limited.
If every string would have its own memory address, the
strings would also be unlimited in size - like in all
other languages.
Internally, the string should be a pointer that holds
the address of the string.
So, for ' A$ = "Test" ' it allocates 5 Bytes of memory with
GlobalAlloc_(), copies "Test" + NULL to this memory and
writes down the address of the string/memory into the internal
variable v_string_A.
Now the coder wrote ' A$ + ": Hello World" '
Internally, the compiler should now get the current length of
the string with GlobalSize_(v_string_A) and save it in a temp
location (register or mem).
Now it makes GlobalReAlloc_() with the old size (4) + size of the
string to add (13) + 1 (ending NULL) and write the address
returned by GlobalReAlloc_() into v_string_A.
Done that, it can copy the new string to v_string_A pointer
+ oldsize and add a NULL at the end.
A pointer to that string, lets say ' *c = @A$ ' tells the
compiler if you use that pointer, it always loads the actual
address of the string from v_string_a internally.
To make a difference with other pointers, a string-pointer
type *c.s would be fine. So the compiler knows this is a
pointer to a string and generates code that doesnt write
to the internal variable pointer_c directly, but to the real
address of the string that is stored in v_string_A.
(So pointer_c contains always the address to v_string_A)
With this way strings could also be 10MB, not limited to 64k.
Its the same with Linked Lists / structures.
String.s in Structures holds always the Pointer returned by
Global(Re)Alloc_() and if you do a DeleteElement(), the
memory gets freed with GlobalFree_().
The size of the string: Len(A$) is internally a simple
GlobalSize_(v_string_A) - 1 (-1 because of the ending NULL).
Hope Fred can change all that for v4.0, so all the string
limits go away.
A good and complete string system isnt very easy to do,
but all other compilers can do that too - so...
At this time especially the 64kb limit can produce very
bad results, because your app just crashes when you make
a string longer than 64k.
Let us hope the year 2003 will change that...
cya,
...Danilo
(registered PureBasic user)
I also thought *c.s is a pointer to a string, because '*' means
_always_ pointer in the PureBasic language.
In my opinion, the whole string stuff in PB isnt very good
and limited.
If every string would have its own memory address, the
strings would also be unlimited in size - like in all
other languages.
Internally, the string should be a pointer that holds
the address of the string.
So, for ' A$ = "Test" ' it allocates 5 Bytes of memory with
GlobalAlloc_(), copies "Test" + NULL to this memory and
writes down the address of the string/memory into the internal
variable v_string_A.
Now the coder wrote ' A$ + ": Hello World" '
Internally, the compiler should now get the current length of
the string with GlobalSize_(v_string_A) and save it in a temp
location (register or mem).
Now it makes GlobalReAlloc_() with the old size (4) + size of the
string to add (13) + 1 (ending NULL) and write the address
returned by GlobalReAlloc_() into v_string_A.
Done that, it can copy the new string to v_string_A pointer
+ oldsize and add a NULL at the end.
A pointer to that string, lets say ' *c = @A$ ' tells the
compiler if you use that pointer, it always loads the actual
address of the string from v_string_a internally.
To make a difference with other pointers, a string-pointer
type *c.s would be fine. So the compiler knows this is a
pointer to a string and generates code that doesnt write
to the internal variable pointer_c directly, but to the real
address of the string that is stored in v_string_A.
(So pointer_c contains always the address to v_string_A)
With this way strings could also be 10MB, not limited to 64k.
Its the same with Linked Lists / structures.
String.s in Structures holds always the Pointer returned by
Global(Re)Alloc_() and if you do a DeleteElement(), the
memory gets freed with GlobalFree_().
The size of the string: Len(A$) is internally a simple
GlobalSize_(v_string_A) - 1 (-1 because of the ending NULL).
Hope Fred can change all that for v4.0, so all the string
limits go away.
A good and complete string system isnt very easy to do,
but all other compilers can do that too - so...
At this time especially the 64kb limit can produce very
bad results, because your app just crashes when you make
a string longer than 64k.
Let us hope the year 2003 will change that...
cya,
...Danilo
(registered PureBasic user)