Delete single element of an array

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Delete single element of an array

Post 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...
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Delete single element of an array

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Delete single element of an array

Post 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
Post Reply