Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Need a way to auto create multiple arrays...

Author
Message
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 2nd Jul 2003 22:43
Im trying to find a way to create multiple arrays without having to declare each one manually. IE make a loop that makes x ammount of "array"x"(0,0,0)" arrays. Here is an example code that doesnt work, but gives you an idea of what im going for...

for a = 1 to maxarray

dim array"+str$(a)+"(0,0,0)

next a

Combining all the arrays into one big array wont work in this situation. I need a way to create and reference arrays via some kind of variable in the array name.

Any way to do this? Thanks in advance
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 2nd Jul 2003 22:50
Quick question - Do empty array positions take up space? The whole point of breaking up a huge array (much of which will be empty) into smaller sections is to save space. Id imagine a 0 still has to take up space, but just want to be sure.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jul 2003 23:07 Edited at: 2nd Jul 2003 23:07
I know what you want, but you can't do it that way with DBPro. That sort of facility is generally only available with interpreted or VM languages.

Until we get arrays with types or arrays within arrays (jagged multi-dimensional arrays), you're not going to get something like this easily.

The only suggestion that I have is to emulate an array using either a memblock or raw memory.

Oh, and memory usage of arrays is quite high - you have 4 bytes for each item, plus the size of each item (eg, 4 for integer), plus a bit of overhead for housekeeping. Strings have 9 bytes plus the length of each string. Unpopulated array items do not reduce memory usage.
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 2nd Jul 2003 23:21
Well thats bad news... hmm I never touched on memblocks, can you give me a example of how to use them in this situation? The showcase example didnt explain much (only delt with two bitmap memblocks).

It says when you declare them you have to give a byte size? Would that be 4*number of integers? So a memblock that holds 100 integers would look like...

make memblock 1,400

Also, are memblocks faster/slower than arrays?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Jul 2003 00:13
No problem



Notes:
No bounds checking has been done - both x and y dimensions have been stored in the memblock, so you could add this
Only 2D - expanding to 3D shouldn't be a problem for you though as it's pretty much more of the same.
I have emulated DBPro array sizing here by allowing you to access from 0 to the size you specify.

Oh, and memblocks will be slower than arrays, but it's probably a bit early to move you onto raw memory access which would only be marginally slower. Stick with using these functions, and it'll be easier to move onto that later if you need the speed.
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 3rd Jul 2003 01:03
Hmm ok so the memblock has to b 4*x however many integer values you want. But whats with the +8?

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 3rd Jul 2003 01:07
You could try my Array DLL - whilst its only for single dimension arrays, you can fiddle it so the value held in one index points to another array and index...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
AzureZeal
23
Years of Service
User Offline
Joined: 10th May 2003
Location:
Posted: 3rd Jul 2003 01:17
Nm figured it out. All I needed was...

for a = 1 to maxmemblock
make memblock a,whateversize
next a

Bingo. unlimited "kinda almost" arrays that i can create and reference via variables.

thanks for the help everyone

Login to post a reply

Server time is: 2026-07-17 21:00:26
Your offset time is: 2026-07-17 21:00:26