Author Topic: Dynamic arrays (any type) with just one 32bit LONG  (Read 6878 times)

0 Members and 1 Guest are viewing this topic.

Offline Eros Olmi

  • Full Member
  • ***
  • Posts: 243
  • User-Rate: +18/-7
    • thinBasic
Dynamic arrays (any type) with just one 32bit LONG
« on: August 06, 2007, 11:01:33 AM »
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

Offline Kent Sarikaya

  • Full Member
  • ***
  • Posts: 174
  • User-Rate: +8/-4
Re: Dynamic arrays (any type) with just one 32bit LONG
« Reply #1 on: December 10, 2007, 09:11:43 AM »
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.

Offline Eros Olmi

  • Full Member
  • ***
  • Posts: 243
  • User-Rate: +18/-7
    • thinBasic
Re: Dynamic arrays (any type) with just one 32bit LONG
« Reply #2 on: December 11, 2007, 11:57:39 AM »
Hi Ken.

I think I've replied to this one here: http://www.jose.it-berater.org/smfforum/index.php?topic=1487.msg4644#msg4644

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

Offline Kent Sarikaya

  • Full Member
  • ***
  • Posts: 174
  • User-Rate: +8/-4
Re: Dynamic arrays (any type) with just one 32bit LONG
« Reply #3 on: December 11, 2007, 10:34:27 PM »
Thanks Eros. Your examples will really help.

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

Thanks again!!