Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing a reference to an array.
#1
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]
Reply
#2
That should work; perhaps you could try it and find out? Wink
Reply
#3
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.
Reply
#4
Does FB have QBX's REDIM PRESERVE?
Reply
#5
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
Reply
#6
Yassir.
Reply
#7
I was first Tongue Hehe we wrote the post at the same time.
Reply
#8
Huh... I just keep learning new crap. I was wondering why something like that wasn't available...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)