Code: Select all
dim as integer ptr mem = allocate (len(integer))
if mem = 0 then print "Allocate failed" : sleep : end
dim as integer ptr d = @mem
deallocate (mem)
Code: Select all
dim as integer ptr mem = allocate (len(integer))
if mem = 0 then print "Allocate failed" : sleep : end
dim as integer ptr d = @mem
deallocate (mem)
Code: Select all
dim as integer ptr mem = allocate (len(integer))
if mem = 0 then print "Allocate failed" : sleep : end
dim as integer ptr ptr d = @mem
deallocate (mem)
Code: Select all
dim as integer ptr mem = allocate (len(integer))
if mem = 0 then print "Allocate failed" : sleep : end
dim as integer ptr d = cast(integer ptr, @mem)
deallocate (mem)
Thanks this helps a lot!fxm wrote: ↑Jan 21, 2023 18:55 'd' is a pointer to the integer pointer 'mem'.
So 'd' is naturally an 'integer ptr ptr':Code: Select all
dim as integer ptr mem = allocate (len(integer)) if mem = 0 then print "Allocate failed" : sleep : end dim as integer ptr ptr d = @mem deallocate (mem)
If you absolutely want to force the 'd' type to 'integer ptr' (I do not see the interest here), you must explicitly cast the assigning variable:Code: Select all
dim as integer ptr mem = allocate (len(integer)) if mem = 0 then print "Allocate failed" : sleep : end dim as integer ptr d = cast(integer ptr, @mem) deallocate (mem)
Code: Select all
dim as integer ptr mem = allocate (len(integer))
*mem = 12345
dim as integer ptr ptr t = @mem
print **t
sleep
deallocate(mem)
Code: Select all
dim as integer ptr mem = allocate (len(integer)*2)
if mem = 0 then print "Allocate failed" : Sleep : end
dim as integer ptr ptr t = @mem
*mem[0]=12345
*mem[1]=54321
print **t[0]
print **t[1]
deallocate(mem)
sleep
Code: Select all
dim as integer ptr mem = allocate (len(integer)*2)
if mem = 0 then print "Allocate failed" : Sleep : end
dim as integer ptr ptr t = @mem
mem[0]=12345 '' 'mem[0]' is equivalent to '*(mem + 0)'
mem[1]=54321 '' 'mem[1]' is equivalent to '*(mem + 1)'
print (*t)[0] '' '(*t)[0]' is equivalent to '*(*t + 0)', parentheses are required in '(*t)[0]' because '[]' takes precedence over '*'
print (*t)[1] '' '(*t)[1]' is equivalent to '*(*t + 1)', parentheses are required in '(*t)[1]' because '[]' takes precedence over '*'
deallocate(mem)
sleep
Thats all i need to know, thanksfxm wrote: ↑Jan 21, 2023 20:03 It gets complicated:Code: Select all
dim as integer ptr mem = allocate (len(integer)*2) if mem = 0 then print "Allocate failed" : Sleep : end dim as integer ptr ptr t = @mem mem[0]=12345 '' 'mem[0]' is equivalent to '*(mem + 0)' mem[1]=54321 '' 'mem[1]' is equivalent to '*(mem + 1)' print (*t)[0] '' '(*t)[0]' is equivalent to '*(*t + 0)', parentheses are required in '(*t)[0]' because '[]' takes precedence over '*' print (*t)[1] '' '(*t)[1]' is equivalent to '*(*t + 1)', parentheses are required in '(*t)[1]' because '[]' takes precedence over '*' deallocate(mem) sleep
Code: Select all
#macro bits(n)
scope
Dim As Integer<n> Ptr mem = Allocate (Len(Integer<n>)*2)
If mem = 0 Then Print "Allocate failed" : Sleep : End
Dim As Integer<n> Ptr Ptr t = @mem
dim as uinteger<n> x=-1
t[0][0]= x\2
t[0][1]=Sizeof(Integer<n>)
Print mem[0]
Print mem[1]
Deallocate(mem)
print
end scope
#endmacro
bits(8)
bits(32)
bits(64)
sleep
Oh, this is MHO. In terms of alignment and cache misses, uint64 vs uint32 fetch faster, but in terms of data packing into uint64, say two uint 32 to one uint64 and then use high and low dword separately for something, will need shifts, to pack back will need and/or sequences.