Dynamic Arrays in User Defined Types - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html) +--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html) +--- Thread: Dynamic Arrays in User Defined Types (/thread-6369.html) |
Dynamic Arrays in User Defined Types - Dr_Davenstein - 03-09-2005 So, I could do it like this? Code: Type ObjType Then when I want to use the new array in a sub... Code: Sub Draw_Entity( Entity as ObjType) Does that look right? EDIT: Ok, that seems to work good, but what about these? Code: RGBA(1 to 50, 3) as Single ''heh oops! How do I allocate a matrix in this method? Would I just do something like this? Code: Type Surface_Properties_Type Then.... Code: Some_Sub(Entity as ObjType) It's kinda hard to get used to... Is it even right? Dynamic Arrays in User Defined Types - lkd85 - 03-09-2005 Pretty much, although you need to subtract 1 from the Num_Surfaces Code: For S = 1 to Entity.Num_Surfaces - 1 Dynamic Arrays in User Defined Types - Dr_Davenstein - 03-09-2005 One more question... Do I need to deallocate these, or will it be automatic? I've tested a few things and I didn't notice any memory leaks... at least this Ram-Booster thing I'm using didn't report any... Is it automatic deallocation when the program ens then? Dynamic Arrays in User Defined Types - Sterling Christensen - 03-09-2005 Quote:Is it automatic deallocation when the program ens then?Windows might do that, but I'm pretty sure you're supposed to deallocate them. Dynamic Arrays in User Defined Types - MystikShadows - 03-09-2005 All this raised another question. Here's a piece of code: Code: TYPE SomeType Can I do this? Or, do I need to pass the address of ThisArray like with the @ symbol ? Dynamic Arrays in User Defined Types - lkd85 - 03-09-2005 You need to pass the address. Have the function return a pointer. Include crt.bi with your program and use MemCpy to copy the return pointer into the new array. Code: TYPE SomeType Dynamic Arrays in User Defined Types - Dr_Davenstein - 03-10-2005 I was trying to rebuild the gl program I made using pointers and I ran into trouble. I made this for a small example... Can anyone show me what I'm doing wrong? I'm not able to access those Callocated arrays from main. :???: Code: Type Vector3DType Dynamic Arrays in User Defined Types - relsoft - 03-10-2005 A better way is to do away with arrays and use straight pointers. ie: Code: type vector That way, you're treating the pointer like a structure Dynamic Arrays in User Defined Types - Dr_Davenstein - 03-10-2005 Ok, but what if you wanted to have vb as an array of models? How do you access that structure in main? Like this... Code: Dim vb(1 to Num_Models) as model ptr Dynamic Arrays in User Defined Types - relsoft - 03-10-2005 Code: vb(vbindex)->verterx[vertexindex].x |