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.

Newcomers DBPro Corner / dynamic memory in dbp

Author
Message
Dsarchy
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: UK- Kent
Posted: 8th Apr 2005 09:53 Edited at: 8th Apr 2005 09:56
is it possible to have dynamic memory in dbp like in C++* so the user (via input) can decide the size of the variable (basicaly create his/her own array)

i could get around it with the use of exporting the information to a file but there must be an easier way of doing it, if anyone can help it would mean alot, thanks all

Dan

edit:
*- i know its possible in other languages aswell this is just an example
an example of dynamic memory in c++:

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 8th Apr 2005 14:55
You set up the dimensions of your array using 'dim'. So for example, if you wanted to enter numbers into an array, as in your c code, you'd do something like



That's a one dimensional array. If you wanted a two dimensional array (say for storing an x and y coordinate), youd say 'dim coordinate(sizex,sizey)'. you can have up to 5 dimensions - but that just wrecks my head!

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 11th Apr 2005 01:56 Edited at: 11th Apr 2005 01:57
Another work around is to use User Defined Types. This is a little easier to handle multi-dimensional arrays as long as they aren't too large after the first array. For example, instead of:



I would use



Then I can assign values in a way that's easily readable. Example:



You can even have UDT's define UDT's to stack them:



This is roughly the equivilent of 3-dimensional array (Dim Ship(20,2,3), but much easier to read (Ship(1).Position.x)

One drawback is that you can't access the extra dimensions using variables like you can in an array (i.e. Ship(a,b,c) ).

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 11th Apr 2005 02:24
DBPros arrays are fully dynamic. You can either use REDIM to re-dimension the array, or there are various stack and queue commands that you can use with arrays, eg...

array insert at bottom
array instert element
array delete element

Look at the help files for the full list.

Isn't it? Wasn't it? Marvellous!

Login to post a reply

Server time is: 2024-09-23 17:27:48
Your offset time is: 2024-09-23 17:27:48