04-17-2005, 01:14 AM
How do I redim a nested UDT array?
say I have
array1.array2.var
and I want to redim array2, how?
say I have
array1.array2.var
and I want to redim array2, how?
Redimensioning nested UDT arrays
|
04-17-2005, 01:14 AM
How do I redim a nested UDT array?
say I have array1.array2.var and I want to redim array2, how?
04-17-2005, 03:05 AM
you can't . i think this was asked before.
anyways the way around this is to simple reallocate the memorey you want i.e. use a pointer in you udt like type foo bar as integer ptr end type foo.bar = allocate(len(bar)*100) then you can access each element with pointer indexing like foo.bar[1] = 40 then when you want more memorey foo.bar = REALLOCATE (foo.bar,len(bar)*400) ' i think i got the syntex right there
04-17-2005, 03:23 AM
What? Thanks for the help ShadowWolf, but why on earth can you not redimension them? Thats just a pain in the ass. Especially as I really dont want to use pointers.
04-17-2005, 03:36 AM
i think it somthing to do with the udt memorey being allocated staticly or somthing ask victor
04-17-2005, 04:58 AM
Why don't you want to use pointer arrays? They're alot more flexible.
04-17-2005, 05:14 AM
Quote:What? Thanks for the help ShadowWolf, but why on earth can you not redimension them? Thats just a pain in the ass. Especially as I really dont want to use pointers. I'm the one that asked that question before ;-). When you think about it, the answer makes sense, and it's also FB's strength, sure it's a bit different to use...but once you get used to it (which shouldn't be too long from now) you'll never want to do without them ;-)....
hen they say it can't be done, THAT's when they call me ;-).
need hosting: http://www.jc-hosting.net All about ASCII: http://www.ascii-world.com
04-17-2005, 06:24 AM
The problem is the cleaning up, FB would have to keep track of the field types at compile-time to automagically deallocate the dynamic field arrays when they get out of scope.
The field coudn't be an array descriptor too, as its dimensions are unknown, so a implicit pointer would be needed (the size of fields must be known to calculate the UDT's sizes), making each array access slower, because the double dereference. The only difference in using pointers is that you gotta use CALLOCATE() instead of REDIM and you must free the memory allocated yourself. To access an pointer index, simply use [] instead of (). With arrays above 1 dimension, pointer indexing can become more complex though..
ew FreeBASIC forums: http://www.freebasic.net/forum/index.php
04-17-2005, 03:27 PM
Ok, thanks guys, I'll use pointers then.
Quote:you must free the memory allocated yourself.How? Sorry, im just a complete noob when it comes to pointers.
04-17-2005, 03:53 PM
with deallocate (pointer goes here)
04-17-2005, 06:31 PM
Ok, so then how would I set up
array1.array2.var? because you said I must dim array2 as integer pointer, it means I cant dim it as another UDT... To make it more clear: [syntax="qbasic"]type buttontype x as integer y as integer xsize as integer ysize as integer end type type windowtype x as integer y as integer xsize as integer ysize as integer title as string numbuttons as integer button(0) as buttontype end type Dim shared win(0) as windowtype[/syntax] And I want to be able to redim button(), how could I set it up? |
« Next Oldest | Next Newest »
|