Posts: 684
Threads: 64
Joined: May 2004
How do I make a sub or function that adds something to an array specified by the parameters? Like "SUB addArray(array() As Integer, newValue As Integer)". Would that work? Tell me if I don't make sense.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Posts: 1,439
Threads: 15
Joined: Apr 2003
That should work; perhaps you could try it and find out?
Posts: 979
Threads: 27
Joined: Aug 2001
Your only practical option is to REDIM the array, and copy the memory.
I wrote some routines that do a real hack-job with reallocate, here:
http://www.freebasic.net/forum/viewtopic.php?t=595
but I'm afraid of reallocating bytes at a time, link-listed dynamic memory is a fickle mistriss who might crash at any time.
Posts: 1,272
Threads: 36
Joined: Feb 2003
Does FB have QBX's REDIM PRESERVE?
Posts: 1,845
Threads: 44
Joined: Aug 2002
Yes.
Code:
Option Dynamic
Private Sub addArray (array() As Integer, newValue As Integer)
Redim Preserve array(UBound(array) + 1) As Integer
array(UBound(array)) = newValue
End Sub
Posts: 1,439
Threads: 15
Joined: Apr 2003
Posts: 1,845
Threads: 44
Joined: Aug 2002
I was first
Hehe we wrote the post at the same time.
Posts: 979
Threads: 27
Joined: Aug 2001
Huh... I just keep learning new crap. I was wondering why something like that wasn't available...