• Welcome to Jose's Read Only Forum 2023.
 

Dynamic arrays (any type) with just one 32bit LONG

Started by Eros Olmi, August 06, 2007, 11:01:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Eros Olmi

I published some time ago a way to dynamically creates arrays at program runtime and handling each of them with just a 32bit LONG.
This open the road to many possibilities especially for handling arrays inside UDT without knowing array size.

Find here attached a copy of the source code with example.
Feel free to use code as you prefer. Code is similar to the one I use internally in thinBasic language to store variable (global or local). Execution is quite fast so even big arrays can be handled quite easily.

The biggest dark side with this approach is that programmer has responsability to deallocate allocate arrays.

Ciao
Eros

---
Max dimensions: 3. Any numeric type, dynamic strings, UDT.
All array information are stored in a structure and a pointer to array structure is returned. This allows easy inclusion of arrays inside UDT or any other data structure. Just a 32bit variable is needed.
thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Kent Sarikaya

Eros, I can't figure out how to use your dynarrays doing something like the following:
type poly_type
    x as double
    y as double
    z as double
    s as byte
    r as integer
    g as integer
    b as integer
    m as long
    u as double
    v as double
    l as long
end type

type m15_type
    number_of_vertices as long
    number_of_layers as long
    layers() as string 'layers
    number_of_polys as long
    p() as poly_type
    number_of_textures as long
    texture_handles() as dword
end type

The m15 would have some arrays that need to be redimmed at runtime once it reads the file. Looking at your example, I couldn't figure out how to make it work in a UDT as I need.
Thanks for any help.

Eros Olmi

thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Kent Sarikaya

Thanks Eros. Your examples will really help.

You know what... an article about dynarrays for pcopy would be very neat!!

Thanks again!!