Page 1 of 1
Easy way to perform a dynamic array
Posted: Fri Oct 07, 2005 10:50 pm
by Psychophanta
This is referred to
viewtopic.php?p=105878
This example shows how can be done a dynamically resizeable variable type and its dimensioned array(s) inside.
Probably it is not very fast if top speed required, but it is good for normal apps.
Code: Select all
Structure su
i.l[0]
EndStructure
*kz.su = AllocateMemory(SizeOf(su))
For t=0 To 300
*kz.su = ReAllocateMemory(*kz.su,(t+1)*SizeOf(su))
*kz\i[t]=5+t
Debug *kz\i[t]
Next
Edit: Updated to PB4.0
Posted: Wed Apr 25, 2007 5:24 pm
by Psychophanta
Previous code does work for PB4.00, but it does not for PB4.02.
Here is the update for 4.02:
Code: Select all
Structure su
i.l[0]
EndStructure
kz.su
For t=0 To 300
kz\i[t]=5+t
Debug kz\i[t]
Next
nice! doesn't

Posted: Wed Apr 25, 2007 6:19 pm
by Fred
You're really writing at forbidden place with your second example..
Posted: Wed Apr 25, 2007 6:21 pm
by Kaeru Gaman
that looks really, really odd for my eyes.
declaring a single variable but using it as a neverending array?
where is memory protection?
when this works, then just because you do not notice how you're shoting your billies....
it's like the famous word:
"I allocate 4 Byte, but write 5 Byte into it. On modern PCs is always enough capacity avaliable, so it will work"
PS:
ok, Fred said it more clearly and less comedian like...
Posted: Wed Apr 25, 2007 6:33 pm
by netmaestro
What's "shoting your billies"

Posted: Wed Apr 25, 2007 6:42 pm
by Kaeru Gaman
that was impro...
meaning "overwriting other memory you have 'billed' (allocated) before"
...was an improvisation using my second language in an "artist" way...
Posted: Wed Apr 25, 2007 6:42 pm
by Psychophanta
Fred wrote:You're really writing at forbidden place with your second example..
Pity that the link i refer in 1st post doesn't work. There you said (when PB3.94) that it was safe.
Well, then
Code: Select all
Structure su
i.l[0]
EndStructure
*kz.su = AllocateMemory(SizeOf(long))
For t=0 To 300
*kz.su = ReAllocateMemory(*kz.su,(t+1)*SizeOf(long))
*kz\i[t]=5+t
Next
For t=0 To 300
Debug *kz\i[t]
Next
Posted: Wed Apr 25, 2007 8:51 pm
by tinman
Psychophanta wrote:Fred wrote:You're really writing at forbidden place with your second example..
Pity that the link i refer in 1st post doesn't work. There you said (when PB3.94) that it was safe.
Perhaps it was safe that zero sized arrays in structs would be safe to use for this purpose in the future (i.e PB4 at the time)?
The link looks like it has an extra digit, I tried various combinations but couldn't find the topic.
Posted: Wed Apr 25, 2007 8:57 pm
by Psychophanta
Hi tinman, you have been offline a lot of months
I believed you dissapeared like Danilo and others
Nah! the link is well written, but i dunno why it doesn't work. It must be lost.
EDIT (2007-10-12): Useless trick, since the invention of ReDim() command:
Code: Select all
Dim kz.l(0); <- use any varible type and/or more than one dimension ;)
For t=0 To 300
ReDim kz(t)
kz(t)=5+t
Next
For t=0 To 300
Debug kz(t)
Next
