Page 2 of 2
Re: Delete single element of an array
Posted: Fri Dec 23, 2011 11:40 pm
by Michael Vogel
Trond wrote:Second point: where in the memory are the strings located?
Strings are just stored as a pointer. The real string could be anywhere.
Sorry, I ment the location of the string pointer, not the string.
As seen in my example, the first structure element (integer value) can be accessed by using the pointer test(i).
But where's the pointer to the second element (string)? A simple test(i)+4 does not work...
Re: Delete single element of an array
Posted: Sat Dec 24, 2011 12:42 am
by Demivec
Michael Vogel wrote:Trond wrote:Second point: where in the memory are the strings located?
Strings are just stored as a pointer. The real string could be anywhere.
Sorry, I ment the location of the string pointer, not the string.
As seen in my example, the first structure element (integer value) can be accessed by using the pointer test(i).
But where's the pointer to the second element (string)? A simple test(i)+4 does not work...
Strings are pointers to pointers to strings.
Code: Select all
For i = 1 To 5
Debug Str(i) + ": @" + Str(test(i)) + ", " + Str(n) + " Byte >> " + Str(PeekI(test(i))) + " = " + PeekS(PeekI(test(i) + OffsetOf(type\text)))
Next
Re: Delete single element of an array
Posted: Sat Dec 24, 2011 3:30 pm
by Trond
Michael Vogel wrote:Trond wrote:Second point: where in the memory are the strings located?
Strings are just stored as a pointer. The real string could be anywhere.
Sorry, I ment the location of the string pointer, not the string.
As seen in my example, the first structure element (integer value) can be accessed by using the pointer test(i).
But where's the pointer to the second element (string)? A simple test(i)+4 does not work...
The pointer is definetely stored at @test(i)+4 in your example, when you compile on 32-bit. On 64-bit the pointer will be at @test(i)+8. Better use OffsetOf(structure\member) to get the correct amount for your platform.
I think your issue is that you're mixing up the address of the pointer with the address of the string data.
@string.s gives the address of the string data.
@test(i)+offsetof(test\text) gives the address of the pointer to the string data. It is not the pointer. It is the address of the pointer.
Code: Select all
Structure type
int.i
text.s
EndStructure
Dim test.type(5)
For i=1 To 5
test(i)\int=Pow(10,i)
test(i)\text=Str(test(i)\int)
Next i
For i=1 To 5
n=test(i)-test(i-1)
Debug Str(i)+": @"+Str(test(i))+", "+Str(n)+" Byte >> "+Str(test(i)\int)+" = "+test(i)\text
Debug Str(i)+": @"+Str(test(i))+", "+Str(n)+" Byte >> "+Str(PeekL(test(i)))+" = "+PeekS(PeekI(@test(i)+OffsetOf(type\text)))
Next i