reDIM in subroutine

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Tomio.

Is it allowed to dimension an array in a subroutine (Gosub), leave the subroutine, come back later and DIM the array anew, or even reDIM the array in another subroutine?

Sometimes my program allowes it, somtimes not (crash). But the behavior is reproducible and always the same with the same array/subroutine combination.

Tomio
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi Tomio
Redim an existing dimension is a really bad coding style... Why not init your DIM at programstart to the maximum you ever need for example? But redim it, isnt really nice and i think it will give a lot memory fragmentation if you want redim it very often...

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

Just want to say that all your arrays data gets lost after a reDim.

Cheers
Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Initializing the DIM at programstart to the biggest value
is a bad coding style, not to use ReDIM if needed.

Dynamically Memory allocation is a very good thing
and not to suck up all memory at program start.

cya
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

using Linked list is the best way for dynamic Data.
Or use pure MEMORY and do Redim byyourself

Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Tomio.

Thanks so far.

Yes I understand that it might not be good programming code to do reDIMs. But it's part of Basic.

My question was: is it ALLOWED to reDIM in different program levels.
I couldn't find info to this point.

When my program crashes in a specific reDIM/subroutine configuration it does so from the first reDIM on, not after the 50th or so.

But I also have a reDIM/subroutine configuration which works fine, but crashes after adding code. This is always a strong hint for memory/boundary errors.

The program is to big to be shown here.

Greetings../tomio
Post Reply